
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? Same question for a downcast (dynamic cast)... Thanks, Dave

"Dave" <better_cs_now@yahoo.com> 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
participants (2)
-
Dave
-
David Abrahams