I have a Base class with virtual destructor and final Derived inheritor:
class Base {
public:
virtual ~Base() {
// some impl
}
};
class Derived final : public Base {
public:
virtual ~Derived() override {
// some other impl
}
};
I have the following questions:
- Does
~Derivedneedsvirtualspecifier? - Should I mark
~Derivedasfinal?
CodePudding user response:
~Derived()will be a virtual destructor, whether you apply the keyword or not. That's because the base class destructor is virtual.~Derived()will be a final overrider, because it is a member of a class which is markedfinal. It does not matter whether you use thefinalkeyword directly on the destructor or not.
