• Automatic lifetime management of objects with
shared_ptr makes shared ownership of resources effective and safe.
• Safe observation of shared resources through
weak_ptr avoids dangling pointers.
• Scoped resources using
scoped_array make the code easier to write and maintain, and helps in writing exception-safe code.
Smart pointers solve the problem of managing the lifetime of resources (typically dynamically allocated objects1). Smart pointers come in different flavors. Most share one key feature—automatic resource management. This feature is manifested in different ways, such as lifetime control over dynamically allocated objects, and acquisition and ...