title: unique_ptr VS auto_ptr
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3451099/stdauto-ptr-to-stdunique-ptr">std::auto_ptr to std::unique_ptr</a><br>
    <a href="https://stackoverflow.com/questions/5026197/what-c-smart-pointer-implementations-are-available">What C++ Smart Pointer Implementations are available?</a>  </p>
  </blockquote>
  
  
  
  <p>Lets say I have this <code>struct</code>:</p>
  
  <pre><code>struct bar 
  { 
  
  };
  </code></pre>
  
  <p>When I use <strong>auto_ptr</strong> like this:</p>
  
  <pre><code>void foo() 
  { 
     auto_ptr&lt;bar&gt; myFirstBar = new bar; 
     if( ) 
     { 
       auto_ptr&lt;bar&gt; mySecondBar = myFirstBar; 
     } 
  }
  </code></pre>
  
  <p>then at <code>auto_ptr&lt;bar&gt; mySecondBar = myFirstBar;</code> C++ transfers the ownership from myFirstBar to mySecondBar and there is no compilation error.</p>
  
  <p>But when I use <strong>unique_ptr</strong> instead of <strong>auto_ptr</strong> I get a compiler error. Why C++ doesn't allow this? And what is the main differences between these two smart pointers? When I need to use what?</p>