C++ 23 · Classes, memory and templates
Own an object with unique_ptr
Allocate an object that is deleted automatically when the pointer goes out of scope. Avoid raw new and delete.
auto p = std::make_unique<Account>(100.0);
std::cout << p->balance() << '\n';
More classes, memory and templates commands
- Define a class
- Use polymorphism
- Share ownership with shared_ptr
- Move instead of copy
- Lock a mutex safely
- Write a function template
All classes, memory and templates commands · C++ 23 cheatsheet