Syntax
#include <memory>
auto user = std::make_shared<User>("Ada");Examples
C++ std::shared_ptr example
A focused example you can adapt while practising.
#include <memory>
auto user = std::make_shared<User>("Ada");Best practices
- Start with the smallest working example, then adapt it to your project.
- Use the language’s standard library and idioms before introducing extra dependencies.
At a glance
- Purpose
- Systems and general-purpose software
- File extension
- .cpp · .hpp
- Runs in
- Compiled native applications
- Usually used with
- Compiler and standard library
Specifications & further reading
Related C++ documentation
C++ Classes & RAII
Classes group data and functions. Constructors establish valid state. C++ uses RAII: an object owns a resource for its lifetime and releases it in its destructor.C++ structs
C++ reference for c++ structs.C++ class access control
C++ reference for c++ class access control.C++ constructor initializer lists
C++ reference for c++ constructor initializer lists.
Classes group data and functions. Constructors establish valid state. C++ uses RAII: an object owns a resource for its lifetime and releases it in its destructor.C++ structs
C++ reference for c++ structs.C++ class access control
C++ reference for c++ class access control.C++ constructor initializer lists
C++ reference for c++ constructor initializer lists.