If I have a base class with a virtual destructor. Has a derived class to declare a virtual destructor too?
class base {
public:
virtual ~base () {}
};
class derived : base {
public:
virtual ~derived () {} // 1)
~derived () {} // 2)
};
Concrete questions:
- Is 1) and 2) the same? Is 2) automatically virtual because of its base or does it "stop" the virtualness?
- Can the derived destructor be omitted if it has nothing to do?
- What's the best practice for declaring the derived destructor? Declare it virtual, non-virtual or omit it if possible?