When to write a destructor? Rule of three/five/zero:
https://en.cppreference.com/w/cpp/language/rule_of_three
That is a cousin of RAII
https://en.cppreference.com/w/cpp/language/raii
What does a destructor do?
1. Execute the statements in its body [A]
2. Invoke the destructors of the class members
3. Invoke the destructors of the base class(es) [B]
[A] If the class explicitly manages a resource, this is the point of release
[B] Plural, if multiple inheritance
1 2 3 4
|
struct Derived : public Base
{
int foo;
};
|
Is it the end of the world, if you don't call the "destructor of
int
"?
That is just an innocent small white lie?
Is it the end of the world, when the next developer sees that you derive from Base and use polymorphism, assumes that Base has virtual destructor, derives an another class, and hell breaks loose?