Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-07-31 08:00:24


From: "Philippe A. Bouchard" <philippeb_at_[hidden]>
> > > [...]
> > > ptr<Derived> pD = new Derived;
> > > ptr<Derived, X> pX = new X;
> > > ptr<Derived, Y> pY = new Y;
> > >
> > > pX = pD; // Won't work
> > > pY = pD; // Won't work
> > > [...]
> >
> > Of course, this syntax is clumsier than existing pointers, and also less
> > powerful. For instance, you may have code that knows about X or Y,
> > but not about anything derived from X or Y. Your proposal requires
> > such code to know about all possible derivatives in order to work
> > properly, which is a fairly restrictive requirement.
>
> Y * pY = new Derived;
> delete pY;
>
> Will result in a segmentation fault.

shared_ptr<Y> pY(new Derived);
pY.reset(); // OK


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