TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  OLC#005Checked automatically with code checker

Synopsis:A virtual method may only be called if an object is fully constructed
Language:C++
Severity Level:1
Category:Object Life Cycle


Description:

A method is made virtual so that derived classes can override it. A derived class overrides a method so that its method, rather then that of its base class is executed.

This does not work when a virtual method is called from for instance the constructor or destructor of a base class. In those cases, the method of the base class is called. In case the base class method is pure virtual it will even lead to an exception.

Less obvious is the situation when during the construction of object X, a handle (pointer/reference) is passed to object Y. Object Y may not call a virtual method of object X, before object X is completely constructed.



Literature References:
Ellemtel 34