Rule of Zero and Rule of Five
Rule of Zero and Rule of Five
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
- Destructor
- Copy Ctor
- Copy Assignment
- Move Ctor
- Move Assignment