
- Forum
- Programming Talk
- C and C++
- Virtual Method Table, Virtual Function Table, Dispatch Table
Virtual Method Table, Virtual Function Table, Dispatch Table
This is a discussion on Virtual Method Table, Virtual Function Table, Dispatch Table within the C and C++ forums, part of the Programming Talk category; Can anyone explain me about Virtual Method Table, Virtual Function Table, Dispatch Table - (VTable) mechanism used in programming language? ...
-
Virtual Method Table, Virtual Function Table, Dispatch Table
Can anyone explain me about Virtual Method Table, Virtual Function Table, Dispatch Table - (VTable) mechanism used in programming language? How does this work? Where we can use these?
-
02-21-2012, 06:47 AM #2
- Join Date
- Feb 2012
- Answers
- 66
Mechanism used in a programming language to support dynamic dispatch (or run-time method binding) is a vtable.
The virtual functions in c++ are implemented using a special form of late binding known as virtual table.The virtual table is a table of functions used to resolve function calls in dynamic binding manner.The virtual table is also known as vtable,virtual method table,virtual function table or dispatch table.
Every class that uses virtual functions (or is derived from a class that uses virtual functions) gets it's own virtual table as a secret data member.
At the compile time the compiler sets the virtual table and this table is simply a static array .
A virtual table contains one entry as a function pointer for each virtual function that can be called by objects of the class.
Virtual table stores NULL pointer to pure virtual functions in ABC.There will be exactly one v-table associated with a class that has at least one virtual function.
There is a pointer for every object which points to the classes vtable known as vptr.The v-table itself has pointers to each of the virtual functions in the class. During a dispatch of a virtual function, the run-time system follows the object's v-pointer to the class's v-table, then follows the appropriate slot in the v-table to the method code.

Reply With Quote





