Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 536
rahul Avatar asked Sep 30 '12 12:09

rahul


2 Answers

No. A vtable only contains pointers to virtual functions in the same class or file.

like image 159
shaveenk Avatar answered Oct 19 '22 17:10

shaveenk


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.

like image 22
CB Bailey Avatar answered Oct 19 '22 19:10

CB Bailey