On Thursday, May 1, 2003, at 04:57 AM, Hossein Haeri wrote:
So the true answer is not to forget to call the reset() member function for every shared_ptr<>, before the end of it's scope.
No, that won't do any good. When you do a reset(), the shared_ptr relinquishes ownership of the thing it points to. If it's the sole owner, it will destroy the object. It's simply an error to put a pointer to a stack object inside a shared_ptr; you can't correct
--- In Boost-Users@yahoogroups.com, Darin Adler
error with a reset() call.
-- Darin
I agree with Darin. Shared_ptr is used for automatically deleting a heap object when the last reference to it (that is, the last copy of the shared_ptr managing it) goes out of scope. It keeps count as the shared_ptr is copied around through parameters and return values and is constructed and destroyed. The underlying count goes up on construction and down on destruction. When the count gets to zero, 'delete' is called on your object. It is used to prevent copies of an object from being made. Hossein, if you'll post a description of what you really want to do, then we might be able to suggest a better idiom for you to follow. jh