static_cast with boost::shared_ptr?

Solution 1:

Use boost::static_pointer_cast:

boost::shared_ptr<Base> b(new Derived());
boost::shared_ptr<Derived> d = boost::static_pointer_cast<Derived>(b);

Solution 2:

There are three cast operators for smart pointers: static_pointer_cast, dynamic_pointer_cast, and const_pointer_cast. They are either in namespace boost (provided by <boost/shared_ptr.hpp>) or namespace std::tr1 (provided either by Boost or by your compiler's TR1 implementation).