
I need to create a class hierarchy where every level inherits from boost::enable_shared_from_this. I am having problems caused, I believe, by having more than one copy of enable_shared_from_this.
I am using boost 1.34.1 with VS2003 and VS2005, with and without ICL9.1, always getting the same result: a boost::bad_weak_ptr exception.
You're right, multiple copies of enable_shared_from_this are unfortunately not supported.
#include
#include using namespace boost;
struct A : enable_shared_from_this<A> { shared_ptr<A> getA() {return enable_shared_from_this<A>::shared_from_this();} }; struct B : A, enable_shared_from_this<B> { shared_ptr<B> getB() {return enable_shared_from_this<B>::shared_from_this();} };
In this case, you can use struct B : A { shared_ptr<B> getB() { return dynamic_pointer_cast<B>( shared_from_this() ); } }; after making A polymorphic.