Search code examples
c++shared-ptr

how to point to a shared_ptr


So I have a shared_ptr in my Main class, and I'd like some other object (a singleton class) to have access to what the shared_ptr is pointing to.

In pseudo code...

mySingletonInstance->somePointer = myShared_ptr;

How do I do that?


Solution

  • If the singleton should participate in shared management of the object that is held by shared_ptr then it's somePointer could be simply a copy of that shared_ptr. Otherwise use a weak_ptr.