Programming FAQ: When should a destructor be virtual?

This is a FAQ, but I always forget the answer. The destructor for a base class should be virtual whenever a derived-class object will be destroyed by calling delete on a base-class pointer.

As a rule of thumb, all classes that have at least another virtual method should have virtual destructors.

However, if a base class has a virtual destructor, all derived class automatically get virtual destructors.

Aug 09, 2004

virtdest (/progtricks)
2004-08-09, 11:34 [edit]


  Login:   Password:   [rss] [cc] [w3] [css]

© M. Vallisneri 2012 — last modified on 2010/01/29

Tantum in modicis, quantum in maximis