From: Dave Handley (dave_at_[hidden])
Date: 2005-01-31 15:25:19
Jonathan Wakely wrote:
> http://boost.org/libs/smart_ptr/enable_shared_from_this.html says:
> enable_shared_from_this<T> must be an accessible base class of T.
I've seen this - but even if I make the inheritance protected, VC++7.1 balks
at it complaining that a conversion from the type T to
enable_shared_from_this is available but inaccessible.
> 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.
I've tried friendship as you recommend, between shared_ptr<T> and policy<T>,
but again without success.
Interestingly, I actually get the error from a construction of a standard
shared_ptr, without even using shared_from_this. I've gone as far as
commenting out every call to shared_from_this in my code. If I inherit from
enable_shared_from_this, the compiler complains on construction of a
shared_ptr in the detail::sp_enable_shared_from_this line in the code below.
If I also comment out enable_shared_from_this, everything compiles okay.
explicit shared_ptr(Y * p): px(p), pn(p, checked_deleter<Y>()) // Y must be
detail::sp_enable_shared_from_this(p, p, pn);
This is remarkably frustrating, since there are a large number of
implementation details in my policy class that I am keen to hide from the
API, and the API works fine for all my other policies, it is just the
shared_ptr policy that is collapsing.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk