Boost logo

Boost :

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


----- Original Message -----
From: "Matthew L. Creech" <mlcreech_at_[hidden]>
To: <boost_at_[hidden]>
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_at_[hidden]>
> 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;
}


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