
----- Original Message ----- From: "Matthew L. Creech" <mlcreech@gmail.com> To: <boost@lists.boost.org> Sent: Friday, October 03, 2008 8:30 AM Subject: Re: [boost] [shared_ptr] Where is the bug?
On Fri, Oct 3, 2008 at 2:26 AM, vicente.botet <vicente.botet@wanadoo.fr> wrote:
EXIT STATUS: 0 Where is the bug?
If you're wondering why X's destructor isn't run, you need to make B's destructor virtual:
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. int main () { shared_ptr<B>* ptr=0; { shared_ptr<X> ptrX1(new X()); ptr = new shared_ptr<B>(ptrX1); } std::cout << "BEFORE" << std::endl; delete ptr; std::cout << "AFTER" << std::endl; B* b = new X(); std::cout << "BEFORE" << std::endl; delete b; std::cout << "AFTER" << std::endl; return 0; }