关于虚函数表的讨论

Virtual function is realized by virtual table usually. 
At there is a virtual table pointer in a class object.
This pointer points to the virtual table.
The virtual table is unique for a class.
Different instances of this class shares the unique table.
Every class has a virtual table if it contains one 
or more virtual functions.
In 32bit system, if get “sizeof”this class, your will
find an additional 4 byte larger
which is for the virtual table.
In virtual table, there are virtual function address records. 
Every record is a pointer to a virtual function
which belongs to the class.
In memory, the virtual table is located at the global sections. 
In a class, the virtual table pointer is at the head of
the class’s memory scope.
Notes:
In a subclass, the functions sequence in the v-table is:
1. subclass derived virtual functions
2. baseclass not derived functions
3. other subclass functions

In this case f is a virtual function which is derived. 
Other functions are normal.
The v-table is like this:

 
A good artical is as below:

http://www.qqread.com/cpp/h387617_2.html

 
 
 
 

posted on 2008-03-21 10:05  dqshll  阅读(227)  评论(0)    收藏  举报

导航