Gotw #5 héritage et destructeur virtual
Je suis en train de faire les exercices de Gotw et voudrais un avis pour l'exercice n°5:
Citation:
delete pb;
This looks innocuous, and it would be if the writer of Base had supplied a virtual destructor. As it is, deleting via a pointer-to-base without a virtual destructor is evil, pure and simple, and corruption is the best thing you can hope for.
...
And the delete, of course, will corrupt your memory anyway and leave things partially destroyed... see the part about virtual dtors above.
Cependant, si rien de spécial ne doit être fait dans les destructeurs, faut-il tout de même en définir un? (dans ce cas-là virtuelle, je l'accorde !)