Can the default destructor be generated as a virtu

2019-03-08 22:52发布

Can the default destructor be generated as a virtual destructor automatically?

If I define a base class but no default destructor, is there a default virtual destructor generated automatically?

7条回答
男人必须洒脱
2楼-- · 2019-03-08 23:49

No. There is a cost associated with making a method virtual, and C++ has a philosophy of not making you pay for things that you don't explicitly state that you want to use. If a virtual destructor would have been generated automatically, you would have been paying the price automatically.

Why not just define an empty virtual destructor?

查看更多
登录 后发表回答