Std::shared_ptr
std::shared_ptr is a C++ standard-library smart pointer that enables multiple owners to share ownership of a dynamically allocated object.
100 C++ Mistakes and How to Avoid Them
std::shared_ptr is a C++ standard-library smart pointer that maintains shared ownership of a dynamically allocated object through reference counting.
- How it is used
- Manages dynamically allocated resources when multiple references share one entity.
- How deep it goes
- Explains RAII-based shared ownership through deque member changes and deletion risks, without detailing pointer internals.
- Examples
- Uses a double-ended queue whose nodes link through shared_ptr, alongside raw-pointer and legacy smart-pointer resource examples.
- What you can do after
- Apply it via std::make_shared to replace raw-pointer ownership in shared-resource structures and reduce deletion code.
Read how 100 C++ Mistakes and How to Avoid Them explains std::shared_ptr →
C++ Concurrency in Action, Second Edition
`std::shared_ptr` is a C++ standard library smart pointer that shares ownership of a dynamically allocated object.
- How it is used
- Returns stack values safely from pop() without allocating during the removal operation.
- How deep it goes
- Demonstrates shared_ptr in a lock-free stack, but leaves node reclamation unresolved.
- Examples
- Uses a lock-free stack whose push allocates shared data and whose pop returns a pointer or an empty value.
- What you can do after
- Apply std::shared_ptr to return stack data without a throwing allocation during pop().
Read how C++ Concurrency in Action, Second Edition explains std::shared_ptr →
Related concepts
- resource acquisition is initializationimplements · Resource acquisition is initialization (RAII) is a resource-management pattern that ties resource ownership and release to the lifetime of an object or scope.
- std::unique_ptralternative to · std::unique_ptr is a C++ standard-library smart pointer that provides exclusive ownership of a dynamically allocated object and manages its lifetime.
- smart pointerkind of · A smart pointer is a pointer-like object that manages or mediates access to a referenced resource, often providing ownership, lifetime, or safety behavior.
- std::experimental::atomic_shared_ptrequivalent to · `std::experimental::atomic_shared_ptr` is a C++ Concurrency TS type that provides atomic operations on shared-pointer ownership.
- popused by · Pop is a collection operation that removes an element according to the collection's defined pop semantics, often returning the removed element or the updated collection.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

