
----- Original Message ----- From: "Emil Dotchevski" <emil@revergestudios.com> To: <boost@lists.boost.org> Sent: Friday, October 03, 2008 8:32 PM Subject: Re: [boost] [shared_ptr] Where is the bug?
On Fri, Oct 3, 2008 at 9:08 AM, vicente.botet <vicente.botet@wanadoo.fr> wrote:
Yes, I know. I was not wondering about why the X's destructor is not run when deleting b, but why the X's destructor is called when deleting ptr.
Because shared_ptr captures the destructor at the time it takes ownership of the object. If this happens when the object is being created (as in your example) the correct destructor is called even if it isn't virtual.
It is common for base types that are designed to be managed by shared_ptr to use protected, non-virtual destructor (watch out for retarded gcc warnings.)
Thanks for your post, What is the advantage to use protected destructor when used with shared pointers? Shouldn't you have a deleter functor? Vicente