Rule of Five in C++

The Rule of Five is a guideline for efficient and bug-free programming in C++. The Rule of Five states that,

If any of the below functions is defined for a class, then it is better to define all of them:

  1. Destructor
  2. Copy Constructor
  3. Copy Assignment Operator
  4. Move Constructor
  5. Move Assignment Operator

(Sometimes this list is made to include the default constructor: Object().)

The Rule of Big Five is an extension of the Rule of Three to include move semantics. The Rule of Three, consists of a destructor, copy constructor, and, copy assignment operator. Use all these three functions when you are dealing with dynamically allocated resources, whereas The Rule of Five includes two more functions i.e. move constructor and move assignment operator.


These five member functions should be implemented consistently. For instance, if you use a deep copy for the copy constructor, the copy assignment operator should make a deep copy, too, and the destructor should deallocate the memory.