bb wrote:
>
Is boost::shared_ptr polymorphic?
i.e., can i do safe downcasting using dynamic_cast?
Almost. dynamic_cast itself won't work, because the compiler doesn't now
about the internals of shared_ptr. But you can use dymamic_pointer_cast,
which applies dynamic_cast to the stored pointer:
#include <memory>
std::tr1::shared_ptr<Basesp0(new Derived);
std::tr1::shared_ptr<Derivedsp1 = dynamic_pointer_cast<Derived>(sp0);
For more details, see section 2.8.3 of my book, "The Standard C++
Library Extensions." (std::tr1::shared_ptr is pretty much the same as
boost::shared_ptr, which it was based on)
--
-- Pete
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.