Skip to main content

Posts

Showing posts with the label VTBL

Virtual Table *_vptr , VTBL, C++

VTBL or VPTR nothing but virtual table and virtual pointer in C++. It gets created when we create function with virtual keyword. As soon as we create the virtual function in a class A table gets created behind the code. BaseClass { virtual void function1(){...} } ChildClass : public BaseClass { virtual void function1(){...}// method overridden. } When we override method that is create another version of function in derived class ChildClass in above case then the *_vptrvirtual void function1(){...}// method overridden. gets created for BaseClass. So VTBL Of Base Class has entry for function1 and Child class will be pointing to that function. *_vptr is nothing but the pointer to function. Note: ones the virtual keyword is introduced all the upcoming functions are considered as virtual. ChildClass: public BaseClass { virtual void function1(){...}// method overridden. void function2(){} } In above case function2 also considered as virtual. BaseClass will not be pointing t...