I am having a base class and i want to convert its this pointer to its derived class shared_ptr. I can`t use inheriting enable_shared_from_this in my case. So is there any other efficient way around?
eg
typedef boost::shared_ptr <a> aPtr;
typedef boost::shared_ptr <b> bPtr;
Class a{
void fun();
}
class b : public a{
}
a::fun(){
//how to carry out this conversion below
bPtr bpointer = dynamic_cast<bPtr>(this);
}
You need
boost::enable_shared_from_this. See the documentation: