I have a resource_manager class that supports std::vector<boost::shared_ptr<resource> > internally. resource_manager is the friend class of resource . I want the resource be created / deleted only by resource_manager , so I made its constructors private (which works fine).
However, if I make the destructor private, the code does not compile because the destructor is called boost::shared_ptr , which is not another resource . Iβm thinking about enforcing the "do not delete by clients" rule, returning only const resource* from resource_manager , but for some reason I am not happy with the security provided by this method (what if the client somehow follows a pointer to non-constant?)
Besides the obvious solution not to use shared_ptr , do you have any solution / best solution to my problem?
source share