As you know, if you want to delete through a pointer to the parent class, the class must have a virtual destructor in order for the delete operator to call the correct destructor of the child class.
But what if I personally do not need a destructor in any of the classes?
Are auto-generated destructors interchangeable?
Or do I still have to add a virtual destructor to the parent class?
As far as I understand, an empty destructor is generated, so nothing will happen when the object is destroyed. Anyway, the compiler is smart and the call to the empty function will be thrown out, respectively, no destructor will be called when deleting.
In this case, it seems strange to add a virtual function, which will be called if this function is nop .
struct A { int x; A(unsigned x) : x(x) {} }; struct B : A { B() : A(7) {} }; int main() { A *a = new B(); delete a; return 0; }