Rule of Zero and Rule of Five

Back

Rule of Zero

Classes that have custom destructors, copy/move assignment should deal with ownership exclusively. Other classes should not have touch with the ownership

class Test {
  std::vector arr;
  public:
  Test(std::vector arr) : arr(arr) {}; // We rely on std::vector to manage it's own resources
};

Rule of Five

When creating a class which is going to manage it’s own resources always define these 5 member functions

  1. Destructor
  2. Copy Ctor
  3. Copy Assignment
  4. Move Ctor
  5. Move Assignment