Rule of Zero/Three/Five
Compiler implicitly genereates 5 default functions if they are needed
and if user haven't declared conflicting versions
1. Default Constructor (ClassName())
2. Destructor (~ClassName())
3. Copy Constructor (ClassName(const ClassName&))
4. Copy Assignment Operator (ClassName& operator=(const
ClassName&))
5. Move Constructor (ClassName(ClassName&&))
6. Move Assignment Operator (ClassName&
operator=(ClassName&&))
Rule of 0: Modern C++ says you should aim to write none of them.
By using smart pointers (std::unique_ptr) and standard containers
(std::vector)
Rule of 3 (Pre-C++11): If a class manages a raw resource, it
needs custom logic for Destructor, Copy Constructor, and Copy Assignment
Operator. If you write one, you almost always need all three to prevent
double-frees or memory leaks.
Rule of 5 (C++11 and later): When C++11 introduced move semantics
for performance, the group expanded to 5. If you manage a raw resource,
you now need to define all five: Destructor, Copy Constructor, Copy
Assignment, Move Constructor, and Move Assignment.