Search code examples
c++boostboost-smart-ptr

Convert boost::shared_ptr to actual class


How would someone do that? for example:

Client* client = it->second;

where it->second is a boost::shared_ptr to Client error:

cannot convert `const ClientPtr' to `Client*' in initialization

Solution

  • boost::shared_ptr has a .get() method to retrieve the raw pointer.

    Documentation here about when and why not to use it: http://www.boost.org/doc/libs/1_44_0/libs/smart_ptr/shared_ptr.htm