A virtual method table, virtual function table, virtual call table, dispatch table, or vtable, is a mechanism used in a programming language to support dynamic dispatch (or run-time method binding).
Suppose a program contains several classes in an inheritance hierarchy: a superclass, Cat
, and two subclasses, HouseCat
and Lion
. Class Cat
defines a virtual function named speak
, so its subclasses may provide an appropriate implementation (e.g. either meow
or roar
).
When the program calls the speak
method on a Cat
pointer (which can point to a Cat
class, or any subclass of Cat
), the calling code must be able to determine which implementation to call, depending on the actual type of object that is pointed to. Because the type of object pointed to by the Cat
pointer is not determined at compile-time, the decision as to which branch to take cannot be decided at compile-time.
There are a variety of different ways to implement such dynamic dispatch, but the vtable (virtual table) solution is especially common among C++ and related languages (such as D and C#). Languages which separate the programmatic interface of objects from the implementation, like Visual Basic and Delphi, also tend to use the vtable approach, because it allows objects to use a different implementation simply by using a different set of method pointers.
Read more about Virtual Method Table: Implementation, Example, Multiple Inheritance and Thunks, Invocation, Efficiency, Comparison With Alternatives
Famous quotes containing the words virtual, method and/or table:
“Neither dead nor alive, the hostage is suspended by an incalculable outcome. It is not his destiny that awaits for him, nor his own death, but anonymous chance, which can only seem to him something absolutely arbitrary.... He is in a state of radical emergency, of virtual extermination.”
—Jean Baudrillard (b. 1929)
“As a science of the unconscious it is a therapeutic method, in the grand style, a method overarching the individual case. Call this, if you choose, a poets utopia.”
—Thomas Mann (18751955)
“... So damn your food and damn your wines,
Your twisted loaves and twisting vines,
Your table dhôte, your à la carte,
. . . .
From now on you can keep the lot.
Take every single thing youve got,
Your land, your wealth, your men, your dames,
Your dream of independent power,
And dear old Konrad Adenauer,
And stick them up your Eiffel Tower.”
—Anthony Jay (b. 1930)