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

后端 未结 4 1244
走了就别回头了
走了就别回头了 2021-02-09 03:45

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

Thx!

4条回答
  •  走了就别回头了
    2021-02-09 04:22

    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.

提交回复
热议问题