Wednesday, July 18, 2007

Crazy compilers

"When you try to delete a derived class object through a base class pointer and the base class has a nonvirtual destructor, the results are undefined. That means compilers may generate code to do whatever they like: reformat your disk, send suggestive mail to your boss, fax source code to your competitors, whatever. (What often happens at runtime is that the derived class's destructor is never called.)"

-Scott Meyer in Effective C++


Moral of the Story :
The next time your email client's sent folder shows a funny email to your boss that you don't remember sending him, be sure to check your code for non-virtual destructors! :-)

No comments: