Monday, October 11, 2010

Calling a Virtual Function in A Base Constructor or Destructor

You should never call a virtual function in a base constructor or destructor.

If your compiler is nice, it will generate code that will tell you this. Otherwise, I maybe hard to debug. Indirect calls to virtual functions add another layer of difficulty to debugging.

References:
   More Exceptional C++ by Herb Sutter. Addison-Wesley, 2002., p. 170.
   http://www.artima.com/cppsource/pure_virtual.html

No comments:

Post a Comment