dimanche 27 janvier 2019

Can a base destructor really be overridden by a derived destructor in C++?

All over the web, as well as in Bjarne Stroustrup's C++ book, I see statements like, "If a base destructor is declared virtual then it is overridden by a derived class's destructor."

But, why is it called overriding? Isn't it slightly different than the "usual" way of overriding functions? By usual, I mean a typical virtual function in a derived class, sharing the same method signature as that in the base. In that usual case, either the base version or the derived version is ignored depending on the actual object pointed to by a pointer.... Let's not get into details of how overriding works in the usual sense.

But in cases of destructors, the base destructor WILL eventually be called, no matter what. Also, its name is different. Why is it then called overriding?

Aucun commentaire:

Enregistrer un commentaire