I think you probably want shared_from_this here.
Update to include David Rodriguez's comments :
Note that shared_from_this() never needs to call an object that is not yet managed by shared_ptr . It's really:
shared_ptr<A> a( new A ); a->createB();
While the following leads to undefined behavior (trying to call delete on a ):
A a; a.createB();
Andrew Durward
source share