Question d’entretien chez Google

Why have virtual destructors?

Réponse à la question d'entretien

Utilisateur anonyme

22 juil. 2010

Due to polymorphic nature of the objects. A destructor is called before the memory associated to an instance is released. You may know the instance is of type A but are not guaranteed it is not of a subtype of A; so rather than follow the inheritance hierarchy to find out which destructor to call, just mark it as virtual and JRE will find it for you; or for GC which would usually be the case for environments with incorporated garbage collector modules.