C++ 23 · Classes, memory and templates
Define a class
A class with a constructor initializer list, a const method and private data.
class Account {
public:
explicit Account(double balance) : balance_(balance) {}
double balance() const { return balance_; }
private:
double balance_;
};
More classes, memory and templates commands
- Use polymorphism
- Own an object with unique_ptr
- 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