Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-20 08:00:01


From: "Brian" <bneal_at_[hidden]>
> --- In Boost-Users_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> ...
> > Yes, shared_ptr will call the destructor. It only requires a
> complete type
> > at construction time.
>
> Hmmm... we tried using shared_ptr today and our destructors were
> still not called. This is with C++ Builder 5.5. I am now trying to
> see if another department has a copy of 6.0 we could try.

What version of boost? Can you post a minimal example? It works here:

testbed.cpp:

#include <boost/shared_ptr.hpp>

class X;

boost::shared_ptr<X> create();

int main()
{
    boost::shared_ptr<X> px = create();
}

testbed2.cpp:

#include <boost/shared_ptr.hpp>
#include <iostream>

class X
{
public:

    X()
    {
        std::cout << "X::X()\n";
    }

    ~X()
    {
        std::cout << "~X::X()\n";
    }

private:

    X(X const &);
    X & operator= (X const &);
};

boost::shared_ptr<X> create()
{
    boost::shared_ptr<X> px(new X);
    return px;
}

Output:

C:\Documents and Settings\pdimov\My Documents\Projects\testbed>bcc32 -v
testbed.cpp testbed2.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
testbed.cpp:
testbed2.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

C:\Documents and Settings\pdimov\My Documents\Projects\testbed>testbed
X::X()
~X::X()


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net