Convert from boost :: shared_ptr <T> to boost :: shared_ptr <const T>
shared_ptr<T>
has a conversion constructor that lets you construct it from shared_ptr<U>
if it is valid to convert from U*
to T*
, reflecting how inline pointers work.
template<typename U>
shared_ptr(const shared_ptr<U>& other);
(For, the std::shared_ptr
constructor can only be called if it U*
converts to T*
, but for boost::shared_ptr
I'm not sure if it checks this, or if you're just getting a compiler error for invalid conversions.)
Since T*
you can convert to const T*
, the constructor lets you create shared_ptr<const T>
from shared_ptr<T>
.
source to share