The
VTABLE is created in the data segment, not on heap, at compile time (not at run
time). Compiler creates only one VTABLE for a class containing virtual method
(including inherited method) and all its object will have VPTR pointer variable
pointing to the VTABLE. The VPTR variable is initialized in default constructor,
copy constructor and assignment operator.
Upcoming Posts
Upcoming Posts....
Make your own partition magic software.
How to make an assembler.
What is booting?
Write a simple OS!
"I have no special talents. I am only passionately curious." - Albert Einstein
Saturday, June 9, 2012
VTABLE Table in C/C++
Non
virtual functions get linked statically. I.e. their addresses along with machine
code of ‘CALL’ assembly instruction are placed to make/resolve method call. However,
to resolve virtual methods, compiler creates a table called VTABLE and puts
address of all the virtual methods in it. With the help of this table, calls to
appropriate method get resolved at runtime. Compiler places code to fetch the
address of virtual method from VTABLE to make a call to the virtual method.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment