Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-05-30 09:18:37


----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>

> compiles with g++ 2.95.2. I don't know about .3.
>
> If we get back to your original example:
>
> class X;
> class Y { shared_ptr<X> p; };
>
> I believe that a compiler is within its rights to reject the code. Members
> of class templates should not be instantiated unless used; however, Y is
not
> itself a template, so the compiler _may_ legitimately generate Y::~Y() at
> the end of Y's definition, which in turn uses
> shared_ptr<X>::~shared_ptr<X>().

On the other hand, the classic (well-known, I think) approach to this
problem is to simply define Y::~Y() out-of-line. There's no magic available:
the laws of physics are not suspended in C++. If the compiler has to
generate Y::~Y(), it has to generate shared_ptr<X>::~shared_ptr(), which of
course requires the definition of X::~X()**

-Dave

**actually, this is recent, because although the standard actually allows
you to delete an incomplete type, we've added code to shared_ptr preventing
that. It's too dangerous.


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