Boost logo

Boost :

Subject: Re: [boost] Subject: Re: [shared_ptr] Where is the bug?
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-10-03 14:18:38


----- Original Message -----
From: "Frank Mori Hess" <frank.hess_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, October 03, 2008 7:53 PM
Subject: Re: [boost] Subject: Re: [shared_ptr] Where is the bug?

>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Friday 03 October 2008 12:39 pm, vicente.botet 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.
>> I
>
> shared_ptr has some magic so it deletes through the same type of pointer
> that
> was passed to its constructor, which can eliminate the need for virtual
> destructors in some cases. Notice how the shared_ptr constructors take
> the
> pointer as a template parameter of the constructor, as opposed to just
> using
> the template type of the shared_ptr itself.

Yeah! Thanks Frank.

The magic is on the default deleter function, which knows the type and so
use delete on the correct type.

shared_ptr is really much more smarter than a raw pointer!

Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk