How to achieve Rule of Zero

We have all heard about the the rule of Five and rule of Zero when it comes to C++ programming. The latter says to avoid implementing any special function as much as possible. When we talk about special member functions, we refer to:

  1. Copy constructor
  2. Copy assignment operator
  3. Move constructor
  4. Move assignment operator
  5. Destructor

Hmm, sounds like a good plan to avoid them, but how? Well, there are a few guidelines that we can follow to achieve that.

  • When we use dynamically allocated objects, we do that through smart pointers
  • When we use dynamic arrays, we should use std::vector<>
  • Always prefer to use containers from the STL when we need to handle collection of objects
  • Use RAII when it comes to resources that need cleanup

Enjoy, coding and never forget that practise is the only way to improve your skills!

References from: