Why should the destructor of base classes be virtual?

前端 未结 5 1273
长情又很酷
长情又很酷 2021-02-05 19:14

in C++: Why should the destructor of base classes be virtual?

5条回答
  •  旧时难觅i
    2021-02-05 19:46

    They dont have to be virtual unless you are using polymorphism. If you do use polymorphism they need to be virtual so that the destructors of inherited classes are guaranteed to be called, so inherited classes can do their clean up.

提交回复
热议问题