boost::shared_ptr has an unusual constructor
template shared_ptr(shared_ptr const & r, T * p);
and I a
For "shared_ptr b(a, dynamic_cast(a.get()));"
I think it is not the recommended way using smart pointer.
The recommended way of doing this type conversion should be:
shared_ptr b(a);
Since in Boost document it is mentioned that:
shared_ptrcan be implicitly converted toshared_ptrwhenever T* can be implicitly converted to U*. In particular,shared_ptris implicitly convertible toshared_ptr, toconst shared_ptrwhere U is an accessible base of T, and toshared_ptr.
In addition to that, we also have dynamic_pointer_cast which could directly do conversion on Smart Pointer object and both of these two methods would be much safer than the manually casting raw pointer way.