I'm reading some notes about shared pointers.
They say the first attempt by STL with the auto_ptr had the following major drawbacks:
This is because once you copy the
auto_ptr into a variable, you forfeit the ownership of the pointer to the new variable.
When you have:
void foo(std::auto_ptr<bar> x);
and you call
foo with an
auto_ptr, you make a copy of the
foo's use. This effectively transfers ownership to
foo and thus the pointer gets deleted after
foo is finished.
This is a really surprising behavior that made me definitively stop using
auto_ptr. For simple RAII inside a
try block (the primary use case of
auto_ptr, as described in books), use