Boost logo

Boost :

Subject: [boost] [shared_ptr] Where is the bug?
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-10-03 02:26:17


Hi,

I have the following program with the following output

#include <iostream>
#include <boost/shared_ptr.hpp>
using namespace boost;
struct B {
    ~B() {
        std::cout << "~B" << std::endl;
    };
};
struct X : B {
    ~X() {
        std::cout << "~X" << std::endl;
    };
    int i;
};

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;
}

BEFORE
~X
~B
AFTER
BEFORE
~B
AFTER
 
EXIT STATUS: 0

Where is the bug?

Vicente

P.S. I'm using g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)


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