
----- Original Message ----- From: "Frank Mori Hess" <frank.hess@nist.gov> To: <boost@lists.boost.org> 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