Dynamic Pointer Cast
问题 I'd like to convert a base class pointer to a derived class pointer as a function argument without using dynamic_pointer_cast class Base { public: typedef std::shared_ptr < Base > Ptr; virtual ~Base ( ); ... }; class Derive : public Base { public: typedef std::shared_ptr < Derive > Ptr; ... }; void foo( Derive::Ptr ptr ) { ... } Base::Ptr ptr1 ( new Derive ); foo( ptr1 ); The above code will give an error while calling foo. This can be avoided by typecasting ptr1 into a Dervie pointer using