please can anyone explain the reason for the following behavior

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

using namespace std;


class A;
typedef boost::shared_ptr<A> A_sptr_t;

class B;
typedef boost::shared_ptr<B> B_sptr_t;

class A : public boost::enable_shared_from_this<A>
{
public:
A() {}
virtual ~A() {}
};


class B : public A, public boost::enable_shared_from_this<B>
{
public:
B() {}
virtual ~B() {}

void f(void)
{
cout << "this is working " << boost::enable_shared_from_this<B>::shared_from_this() << endl;
}
};


int main()
{
B_sptr_t b(new B());
b->f();
return 0;
}




the program will be terminated with the following message

terminate called after throwing an instance of 'boost::bad_weak_ptr'
what(): boost::bad_weak_ptr
Aborted


--
Regards,
R. P. Janaka