Boost logo

Boost :

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


From: "Larry Evans" <jcampbell3_at_[hidden]>
> Thomas Maeder wrote:
>
> > Am 2002.01.19 14:23 schrieb(en) David Abrahams:
> > >
> > > ...which is the reason it might be better if they didn't implicitly
> > > convert, unless Peter's precautions are taken.
> >
> > Are there equivalent precautions against
> >
> > shared_ptr<Base> b(new Derived);
> >
> > ?
> >
>
> The following test driver snippet:

[...]

> where "struct subjAB :public A,public B{...}", when compiled and run with
> "gcc version 3.1 20011207 (experimental)", fails to delete a_make.
>
> I am using Peter's
http://groups.yahoo.com/group/boost/files/smart_ptr_3.zip.

True, there is no way to detect the general case where a shared_ptr is being
constructed from a T * that actually points to something derived from T.

Easy cases like the above example can be detected (QoI) but in general, it
is a precondition of the shared_ptr(T * p) constructor that "delete p" will
work, and it is the user's responsibility to meet that precondition.

Once the pointer has been successfully constructed (the precondition has
been met) it becomes shared_ptr's responsibility to do the right thing on
destruction.

--
Peter Dimov
Multi Media Ltd.

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