Library 1. Smart_ptr

How Does the Smart_ptr Library Improve Your Programs?

• 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_ptr and 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 ...

Get Beyond the C++ Standard Library: An Introduction to Boost now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.