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:
- Copy constructor
- Copy assignment operator
- Move constructor
- Move assignment operator
- 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: