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!
==Implementation== <!-- [[Virtual function pointer]] redirects here --> An object's virtual method table will contain the [[Memory address|addresses]] of the object's dynamically bound methods. Method calls are performed by fetching the method's address from the object's virtual method table. The virtual method table is the same for all objects belonging to the same class, and is therefore typically shared between them. Objects belonging to type-compatible classes (for example siblings in an inheritance hierarchy) will have virtual method tables with the same layout: the address of a given method will appear at the same offset for all type-compatible classes. Thus, fetching the method's address from a given offset into a virtual method table will get the method corresponding to the object's actual class.<ref>Ellis & Stroustrup 1990, pp. 227β232</ref> The [[C++]] standards do not mandate exactly how dynamic dispatch must be implemented, but compilers generally use minor variations on the same basic model. Typically, the compiler creates a separate virtual method table for each class. When an object is created, a pointer to this table, called the '''virtual table pointer''', '''vpointer''' or '''VPTR''', is added as a hidden member of this object. As such, the compiler must also generate "hidden" code in the [[Constructor (object-oriented programming)|constructor]]s of each class to initialize a new object's virtual table pointer to the address of its class's virtual method table. Many compilers place the virtual table pointer as the last member of the object; other compilers place it as the first; portable source code works either way.<ref> Danny Kalev. [http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=196 "C++ Reference Guide: The Object Model II"]. 2003. Heading "Inheritance and Polymorphism" and "Multiple Inheritance". </ref> For example, [[g++]] previously placed the pointer at the end of the object.<ref>{{cite web |url=http://www.codesourcery.com/public/cxx-abi/cxx-closed.html |title=C++ ABI Closed Issues |access-date=2011-06-17 |url-status=bot: unknown |archive-url=https://web.archive.org/web/20110725153606/http://www.codesourcery.com/public/cxx-abi/cxx-closed.html |archive-date=25 July 2011}}</ref>
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)