I'm using multiple inheritance like this:
struct A {
virtual ~A(){}
};
struct B {
virtual void foo() = 0;
protected:
~B(){} // never called directly
};
struct C : public A, public B {
virtual void foo(){};
};
Should the destructor of B be made virtual or not? On one hand, all the other destructors are virtual around here. On the other hand, there probably is some cost involved with virtual constructors, so why not save this?
A good rule of thump is to make the destructor virtual until you find a good reason that it shouldn't be virtual. This will help you avoid bugs in the future and if in the future, you find that you are getting a big performance hit because of it then you can easily remove it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With