|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-01-21 22:28:11
"Dave" <better_cs_now_at_[hidden]> writes:
> Hello NG,
>
> With regard to shared_ptr<>...
>
> Let's say I have a heap object of type O that contains one subobject of type
> SO. At this point, I'm deliberately not saying whether the subobject is
> brought into the object by public inheritance or by containment. Either
> way, the memory layout is the same under most implementations.
>
> May I upcast shared_ptr<O> to shared_ptr<SO> in any case? Or, does the
> answer depend on whether the subobject has been brought in by public
> inheritance or by containment?
The latter. You can only do the upcast if the subobject has been
brought in by public inheritance. The rules are the same as for
pointers.
> Same question for a downcast (dynamic cast)...
Ditto, though you can't use dynamic_cast; you have to use
dynamic_pointer_cast as described in
http://www.boost.org/libs/smart_ptr/shared_ptr.htm
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk