Monday, October 25, 2010


When the current owner goes out of scope, the object that the auto_ptr is pointing to, is deleted by the auto_ptr<T>.

When a function returns an auto_ptr<T> by value, but the caller does not store the return value; The auto_ptr<T>'s object will be automatically deleted, so there will be no memory leak.

Reference: Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions by Herb Sutter. Addison-Wesley, 1999, pp. 154-155.

No comments:

Post a Comment