This is due to the fact that after copying auto_ptr into a variable, you lose ownership of the pointer to the new variable.
If you have:
void foo(std::auto_ptr<bar> x);
and you call foo with auto_ptr , you make a copy of auto_ptr for foo . This effectively transfers ownership of foo , and therefore the pointer will be deleted after foo completes.
This is really amazing behavior that made me permanently stop using auto_ptr . For simple RAII inside a try block (a basic example of using auto_ptr , as described in books), use boost::scoped_ptr .
source share