C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Features and Keywords of Version 2 Native C++
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
E-6
Defining Virtual Function Tables
Defining Virtual Function Tables
Virtual function tables are defined when virtual functions are defined. (These tables are
merely declared when there are virtual function declarations.) If a program declares but
does not define a virtual function, the declaration exists without the required definition
of its corresponding virtual function table (as per the standard).
The native C++ compiler generates a virtual function table for only one translation unit
in a program when at least one virtual function is not defined with its class definition.
The translation unit selected is the one that contains the definition of the lexically first
non-inline virtual member function. Duplicate virtual function tables are generated for
classes that define all virtual member functions within the class definition.
Example
class A {
virtual int foo (); // foo not defined within its class
}; // A's virtual function table will be defined within the
// module that contains the definition of A::foo.
class B{
virtual int foo() {return 1;}
}; // all of B's virtual functions are defined within
// B's definition, so each module that contains B also
// contains a definition for B's virtual function table.