Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] Where is the bug?
From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-10-03 14:32:58

On Fri, Oct 3, 2008 at 9:08 AM, vicente.botet <vicente.botet_at_[hidden]> 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.)

Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at