<<< Under the covers | Index | Two forms of inheritance >>> |
Destructors of base classes should be declared virtual:
class Shape { public: virtual void draw() = 0; // pure virtual virtual ~Shape(); // virtual destructor };//class Shape
Otherwise, destruction of a derived object via a base reference or pointer is (gasp!) undefined...
...so even the base part may not be properly destroyed!
This means you can't really safely inherit from classes with non-virtual destructors.
Maybe just make all destructors virtual?
Well, this is a size issue.
Any class with a virtual function should certainly have a virtual destructor.
<<< Under the covers | Index | Two forms of inheritance >>> |