A
vtable is the common name for a special data structure used by some
C++ compilers. The vtable, short for "virtual table", is used to
dynamically bind virtual functions to
objects at
runtime. The vtable is not intended to be used directly by the program, and as such there is no standardized way to access it.
A vtable typically stores pointers to all of the virtual functions within a class. It is used at runtime by the C++ program to dynamically bind the proper methods to an object. Each object of a class with virtual functions transparently stores a pointer to its vtable. A call to a virtual function is resolved by following this hidden vtable pointer and from there it gets the address of the virtual function. Virtual base classes are handled in a similar same way; one implementation uses an additional level of indirection for the base class.
The C++ notation for a pure virtual function, "= 0", is directly linked to its original representation in the vtable as a null pointer in the original cfront C++ translator.
This allows the proper function to be called, even if the object is being referenced through a base class. This is a key requirement for the OO concept of polymorphism, where a specialized object can be treated as a more generic object, yet retain its specialized behavior.