I am trying to learn how to use smart pointers and understand ownership. When I pass an auto_ptr
to a function by value, the function takes exclusive ownership of that pointer. So when the function finishes up, it deletes the pointer that I passed to it.
However, I get a compile error when I try doing this with a unique_ptr
, as if copy assignment is disabled for unique_ptr
s. Passing a unique_ptr
by reference does not seem to transfer ownership, it merely gives the function a reference to the unique_ptr
.
How do I get auto_ptr
's behavior with passing ownership to function to work with unique_ptr
s? I would appreciate a link to a detailed tutorial on unique_ptr
, as so far the ones I've read seem to only talk about auto_ptr
or talk about the smart pointers available with Boost and seem to ignore unique_ptr
because shared_ptr
covers it.