C++ 23 · Classes, memory and templates
Share ownership with shared_ptr
The object is deleted when the last shared_ptr to it goes away.
auto a = std::make_shared<Account>(50.0);
auto b = a;
std::cout << a.use_count() << '\n';
More classes, memory and templates commands
- Define a class
- Use polymorphism
- Own an object with unique_ptr
- Move instead of copy
- Lock a mutex safely
- Write a function template
All classes, memory and templates commands · C++ 23 cheatsheet