Search code examples
c++virtualvtable

c++: Does a vtable contains pointers to non-virtual functions?


vtable contains pointers to virtual functions of that class. Does it also contains pointers to non-virtual functions as well?

Thx!


Solution

  • It's an implementation detail, but no. If an implementation put pointers to non-virtual functions into a vtable it couldn't use these pointers for making function calls because it would often cause incorrect non-virtual functions to be called.

    When a non-virtual function is called the implementation must use the static type of the object on which the function is being called to determine the correct function to call. A function stored in a vtable accessed by a vptr will be dependent on the dynamic type of the object, not any static type of a reference or pointer through which it is being accessed.