Smart Pointer Programming Techniques
Using incomplete classes for implementation hiding
The “Pimpl” idiom
Using abstract classes for implementation hiding
Preventing delete px.get()
Using a shared_ptr
to hold a pointer to an array
Encapsulating allocation details, wrapping factory functions
Using a shared_ptr
to hold a pointer to a statically allocated object
Using a shared_ptr
to hold a pointer to a COM object
Using a shared_ptr
to hold a pointer to an object with an embedded reference count
Using a shared_ptr
to hold another shared ownership smart pointer
Obtaining a shared_ptr
from a raw pointer
Obtaining a shared_ptr
(weak_ptr
) to this
in a constructor
Obtaining a shared_ptr
to this
Using shared_ptr
as a smart counted handle
Using shared_ptr
to execute code on block exit
Using shared_ptr<void>
to hold an arbitrary object
Associating arbitrary data with heterogeneous shared_ptr
instances
Using shared_ptr
as a CopyConstructible mutex lock
Using shared_ptr
to wrap member function calls
Delayed deallocation
Weak pointers to objects not managed by a shared_ptr