Reputation: 12949
I know that virtual
propagates to the derived class method and it's optional to put as keyword on the method declaration on the derived class, and i know that i MUST mark as virtual
the destructor of the base class, in order to have polymorphic destruction, but what i want to know is if the default destructor of the derived class, inherit the virtual
from the virtual destructor of the base class, and so i have to explicit write it on the derived class.
Example:
class A{
public:
virtual ~A() override = default;
}
class B: public A{
public:
// have i to write this or it's already what the compiler get as default?
virtual ~B() override = default;
}
Upvotes: 0
Views: 185
Reputation: 76448
The destructor for a derived class, despite having a different name from the destructor of the base class, overrides the base class destructor. Just like any other override, it’s virtual if the one it overrides is virtual.
Upvotes: 2