Whenever a class member function is declared as virtual, the compiler creates a virtual table in
memory which contains all function pointers that are declared as virtual in that class. This enables
run time polymorphism (i.e. finding out the desired function at run time). Virtual function tables
also have an additional pointer in the object to the vtable. As this additional pointer and the vtable
increases the size of the object, a class designer needs to be judicious about declaring functions
virtual. The sequence of events upon calling a method on the base object pointer is:
• Get vtable pointer (this vtable pointer points to the beginning of the vtable).
• Get the function pointers in the vtable using offset.
• Invoke the function indirectly through the vtable poin
memory which contains all function pointers that are declared as virtual in that class. This enables
run time polymorphism (i.e. finding out the desired function at run time). Virtual function tables
also have an additional pointer in the object to the vtable. As this additional pointer and the vtable
increases the size of the object, a class designer needs to be judicious about declaring functions
virtual. The sequence of events upon calling a method on the base object pointer is:
• Get vtable pointer (this vtable pointer points to the beginning of the vtable).
• Get the function pointers in the vtable using offset.
• Invoke the function indirectly through the vtable poin
Comments
Post a Comment
https://gengwg.blogspot.com/