Jan 21, 2009

If the class only has member functions, the sizeof(class) is 1, if the class has virtual function, the sizeof(class) is 4 because vtpr which point to

If the class only has member functions, the sizeof(class) is 1, if the class has virtual function, the sizeof(class) is 4 because vtpr which point to vtable is added.
each class which has virtial function has a virtual table, if derived class overwrite a virtual function from base class, in derived class’s virtual table, this virtual function address is point to new virtual function. If the function is just inherited from base class, rather than overwrite, in derived class’s virtual table, this function address is point to old function of base class
Virtual table: http://en.wikipedia.org/wiki/Virtual_method_table

No comments:

Post a Comment