Reference counted smart pointer class implementing shared ownership
A shared_ptr
is a non-intrusive smart pointer that manages the ownership of a shared resource. Multiple shared_ptr
objects can share ownership of the same resource, which will be destroyed automatically when there are no more "non-empty" shared_ptr
objects referring to it.
The different versions and implementation commonly used are boost::shared_ptr
(the original), std::shared_ptr
(included in the C++11 standard) and std::tr1::shared_ptr
(from the TR1 report on library extensions, lacks certain features such as aliasing).
The related class template weak_ptr
is designed for use with shared_ptr
and represents a non-owning reference to a resource that is managed by a shared_ptr
. This useful to avoid circular references. A weak_ptr
can also be used as a "tracking reference" and converted to a shared_ptr
to temporarily assume shared ownership when it is required.