I have a small question about virtual destructors. It's well known that if we have an abstract class A
(a polymorphic class) we should declare the destructor of A
virtual.
However, assume that we have B
, a derived class of A
, and C
is a derived class of B
. In B
, we redefine all virtual methods of A
to make sure that B
is not again an abstract class.
My question is wether we should declare the destructor of B
virtual or not for the sake of its derived class such as the class C
.
struct A {
virtual ~A() = default; // Good practice: virtual here
virtual void foo() = 0;
};
struct B : A {
virtual ~B() = default; // Is virtual required here?
void foo() { }
};
struct C : B {
};
Thanks in advance!