As James has well covered you can't really detach a shared pointer.
Do you need multiple owners internally, or are you transferring ownership from your class to the client? In that case a std::auto_ptr
might fit the bill.
If you're worried about the surprising semantics of std::auto_ptr
, you could hold it internally by boost::scoped_ptr
, and detach it at the point you hand it out - leaving it up to the client to manually delete it or store it in their own smart pointer.
If you do have multiple owners on your side you could use an intrusive count. Internally you could then use boost::intrusive__ptr
, but hand off the raw pointer at the interface. The client can then either manually work with ref counts, or store it in a boost::intrusive_ptr
themselves (but you don't make them depend on it)