Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-03-22 09:08:59


From: "E. Gladyshev" <egladysh_at_[hidden]>
> The point is that the fool() is fool and
> he doesn't want to know how to make or follow
> any memory mananagement/ownership contracts :).
>
> Would not it be great if shared_ptr<>
> could figure out automatically that the
> pointed object has not been allocated
> dynamically so it should not call
> delete even wnen nobody references
> the object.

There is no way (or need) to make shared_ptr omniscient.

When you construct a shared_ptr, it is your responsibility to specify how
should the object be deallocated. In other words, the caller of fool(), who
presumably allocates the object, should construct a shared_ptr with an
appropriate deallocator. fool() then should receive a shared_ptr as an
argument and not a plain pointer.


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