Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-10-02 14:28:54


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).


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net