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

user53670 picture user53670 · Jul 13, 2009 · Viewed 27.9k times · Source

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?

Answer

Uri picture Uri · Jul 13, 2009

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?