Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Virtual method table
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Mechanism for supporting dynamic dispatch}} {{redirect|Virtual table|virtual tables in SQL|View (SQL)}} {{Use dmy dates|date=January 2021}} In [[computer programming]], a '''virtual method table''' ('''VMT'''), '''virtual function table''', '''virtual call table''', [[dispatch table]], '''vtable''', or '''vftable''' is a mechanism used in a [[programming language]] to support [[dynamic dispatch]] (or [[Run time (program lifecycle phase)|run-time]] method [[name binding|binding]]). Whenever a [[Class (computer programming)|class]] defines a [[virtual function]] (or [[Method (computer programming)|method]]), most [[compiler]]s add a hidden [[member variable]] to the class that points to an array of [[Pointer (computer programming)|pointer]]s to (virtual) functions called the virtual method table. These pointers are used at runtime to invoke the appropriate function implementations, because at compile time it may not yet be known if the base function is to be called or a derived one implemented by a class that [[Inheritance (object-oriented programming)|inherits]] from the base class. There are many different ways to implement such dynamic dispatch, but use of virtual method tables is especially common among [[C++]] and related languages (such as [[D (programming language)|D]] and [[C Sharp (programming language)|C#]]). Languages that separate the programmatic interface of objects from the implementation, like [[Visual Basic]] and [[Delphi (programming language)|Delphi]], also tend to use this approach, because it allows objects to use a different implementation simply by using a different set of method pointers. The method allows creation of external libraries, where other techniques perhaps may not.<ref name=inria-00565627>{{ cite book | url=https://hal.inria.fr/inria-00565627/document |title=Efficient Dynamic Dispatch without Virtual Function Tables: The SmallEiffel Compiler -- 12th Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA'97), ACM SIGPLAN, Oct 1997, Atlanta, United States. pp.125-141. inria-00565627 |page=16 |first1=Olivier |last1=Zendra |first2=Dominique |last2=Colnet |first3=Suzanne |last3=Collin |date=1997 |publisher=Centre de Recherche en Informatique de Nancy Campus Scientifique, Bâtiment LORIA }}</ref> Suppose a program contains three classes in an inheritance hierarchy: a [[Superclass (computer science)|superclass]], {{mono|Cat}}, and two [[Subclass (computer science)|subclasses]], {{mono|HouseCat}} and {{mono|Lion}}. Class {{mono|Cat}} defines a [[virtual function]] named {{mono|speak}}, so its subclasses may provide an appropriate implementation (e.g. either {{mono|meow}} or {{mono|roar}}). When the program calls the {{mono|speak}} function on a {{mono|Cat}} reference (which can refer to an instance of {{mono|Cat}}, or an instance of {{mono|HouseCat}} or {{mono|Lion}}), the code must be able to determine which implementation of the function the call should be ''dispatched'' to. This depends on the actual class of the object, not the class of the reference to it ({{mono|Cat}}). The class cannot generally be determined ''statically'' (that is, at [[compile time]]), so neither can the compiler decide which function to call at that time. The call must be dispatched to the right function ''dynamically'' (that is, at [[run time (program lifecycle phase)|run time]]) instead.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)