There is this question on stackoverflow which advocates Scott Meyers rule of only making a destructor virtual if there are virtual functions in that class.
I am working in a company with a large framework and it is unclear at coding time if your class might be extended in the future. At that point in time it might also be impossible to change that class (because it is part of a released bundle).
Now imagine the following scenario:
class A {
public:
A();
virtual ~A();
virtual m();
};
class B : public A {
public:
B();
~B();
};
class C : public B {
public:
C();
virtual ~C();
virtual m();
};
So I created class B
and by now, it cannot be changed.
Now class C
is created, and is used as a B
:
B * b = new C();
delete b;
What will happen is that the destructor of C is never called, right?
Within this scenario: Should a class always have a virtual destructor?