title: what's the point of auto_ptr & unique_ptr?
body: <p>I just can't understand the meaning of unique_ptr or auto_ptr, as we all know, once the parameter gets out of its scope, we won't get memory leaks. However, is it a better idea if I create the parameter on the stack rather on the heap. I don't see its advantage over normal parameters. If we really need to create parameters on the heap, then we must use <code>new</code> operator, right?</p>
  
  <p>Here is a little code snippet:</p>
  
  <pre><code>class Base
  {
  public:
      Base()
      {
          cout &lt;&lt; "Base::()" &lt;&lt; endl;
      }
      virtual ~Base()
      {
          cout &lt;&lt; "~Base()" &lt;&lt; endl;
      }
  
      virtual void iPhone()
      {
          cout &lt;&lt; "I'm iPhone5s" &lt;&lt; endl;
      }
  };
  
  class Derive : public Base
  {
  public:
  
      Derive()
      {
          cout &lt;&lt; "Derive()" &lt;&lt; endl;
      }
  
      virtual void iPhone()
      {
          cout &lt;&lt; "I'm iPhone 6" &lt;&lt; endl;
      }
  
      virtual ~Derive()
      {
          cout &lt;&lt; "~Derive()" &lt;&lt; endl;
      }
  };
  
  void main()
  {
    {
  
        auto_ptr&lt;Base&gt; ptr(new Derive());//a foolish idea to do so?
        ptr-&gt;iPhone();
  
        Derive d;//isn't it better?
        Base* base = &amp;d;
        base-&gt;iPhone();
   }
  }
  </code></pre>