Possible Duplicate:
std::auto_ptr to std::unique_ptr
What C++ Smart Pointer Implementations are available?

Lets say I have this struct:

struct bar 
{ 

};

When I use auto_ptr like this:

void foo() 
{ 
   auto_ptr<bar> myFirstBar = new bar; 
   if( ) 
   { 
     auto_ptr<bar> mySecondBar = myFirstBar; 
   } 
}

then at auto_ptr<bar> mySecondBar = myFirstBar; C++ transfers the ownership from myFirstBar to mySecondBar and there is no compilation error.

But when I use unique_ptr instead of auto_ptr 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?

Edit
Report