Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-01-31 05:10:47


On Mon, Jan 31, 2005 at 12:06:46AM -0000, Dave Handley wrote:

> I wonder if anyone could help me with a particular problem I'm having with
> shared_ptr. I'm working on a policy template, and I want the policy
> template to both privately inherit, and inject enable_shared_from_this -
> but the 2 things seem to be mutually exclusive.

http://boost.org/libs/smart_ptr/enable_shared_from_this.html says:

    Requires:
        enable_shared_from_this<T> must be an accessible base class of T.

In order for the shared_ptr<T> constructor to initialise the
enable_shared_from_this<T>::_internal_weak_this member of the object it
owns, it must be able to access the base class.

Obviously using public inheritance works, but you might also be able to
make it work by making shared_ptr<T> a friend of policy<T> so it can do
the conversion. You'll also need to disable the BOOST_ASSERTs in
enable_shared_from_this.hpp by defining BOOST_DISABLE_ASSERTS or by
copying enable_shared_from_this.hpp and re-implementing the class
without the assertions. I have no idea if this is supposed to work, nor
if it will still work if the internals of shared_ptr or
enable_shared_from_this change. Caveat emptor.

jon

-- 
"It has always been the prerogative of children and half-wits to point out
 that the emperor has no clothes.  But the half-wit remains a half-wit, and 
 the emperor remains an emperor."
	- Neil Gaiman

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