C++ Language/Indirection/SmartPointers/OwnershipCycle

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The std::weak_ptr<> type is for situations where you need access to the shared memory payload that is being collectively managed by several std::shared_ptr<>, but you don't want this std::weak_ptr<> to affect the reference count. A cyclic data structure is one example where that is needed.

Additional information about weak_ptr (includes interactive examples)