2 Oct
2007
2 Oct
'07
6:28 p.m.
Andrew Holden:
Peter Dimov wrote:
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.
Is there any reason you couldn't use static_pointer_cast? You know for a fact that the cast to B will work, as getB is a member function of B. I think this will also remove the need to make A polymorphic.
static_pointer_cast will work too, as long as no virtual inheritance is involved (D: C, D: B, B: A, C: A).