Question d’entretien chez Yahoo

Why do we need virtual destructor in c++

Réponses aux questions d'entretien

Utilisateur anonyme

8 nov. 2013

When we destroy objects of derived classes, the derived class's dtor is called first, then the base class's dtor. But the derived dtor may free/destroy members from the base class. This is a problem when the base class's dtor is called. Making the base class's dtor virtual, prevents the base class dtor from being called, assuming that the derived class has defined it's own dtor. General rule, is if you have a class inherit from another, make the base class virtual.

1

Utilisateur anonyme

1 févr. 2021

The key in these questions is to cover the fundamentals, and be ready for the back-and-forth with the interviewer. Might be worth doing a mock interview with one of the Yahoo or ex-Yahoo Technical Yahoo experts on Prepfully? They give real-world practice and guidance, which is pretty helpful. prepfully.com/practice-interviews