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_ptr
can be implicitly converted toshared_ptr
whenever T* can be implicitly converted to U*. In particular,shared_ptr
is implicitly convertible toshared_ptr
, toconst shared_ptr
where 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.