The ‘Rule of Five’ in C++11 and later states that if a class defines one special member function, it should define all five. These functions are the destructor, copy constructor, copy assignment operator, move constructor, and move assignment operator.
Example of Rule of Five:
class MyClass {
public:
MyClass() = default;
~MyClass() = default;
MyClass(const MyClass&) = default;
MyClass& operator=(const MyClass&) = default;
MyClass(MyClass&&) noexcept = default;
MyClass& operator=(MyClass&&) noexcept = default;
};
Leave a Reply