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.


#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>

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();}
};

int main()
{
    shared_ptr<A> pA (new A);
    pA->getA(); // this works OK

    shared_ptr<B> pB (new B);
    pB->getB(); // throws boost::bad_weak_ptr() !?

    return 0;
}


question 1: Is this expected or am I doing something wrong?
question 2: If it is expected: is it possible to have it explained in the documentation?
question 3: Is there a way to accomplish this (inheritance with shared_from_this in all levels) using enable_shared_from_this?

Thanks in advance