If derived class will be having vtable then why we need vtable for derived class?
What happens to VTABLE when base class has virtual function and derived class does?
Collapse
X
-
The vtable identifies what function to call when you call a virtual function on an object.
Every class has a vtable if that class has a virtual function.
In your case, base objects have a vtable that will call the base class version of the virtual function. Derived objects will have a vtable that calls the derived class version of the virtual function.
If there is no derived class version of the virtual function, then the derived class vtable will call the base class version of the virtual function. -
If the base class does NOT have a virtual function and the derived class does NOT have a virtual funciton, then neither class gets a vtable.
If the base class has a virtual function, then the derived class has a virtual function, whether the virtual keyword is used or not. Virtual functions don't go away after a class has been inherited.Comment
Comment