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

后端 未结 4 1678
Happy的楠姐
Happy的楠姐 2021-02-09 03:28

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:26

    No, it doesn't.

    As calls to non-virtual methods can be resolved during compilation (since compiler knows the addresses of non virtual functions), the compiler generates instructions to call them 'directly' (i.e. statically).

    There is no reason to go through vtable indirection mechanism for methods which are known during compiling.

提交回复
热议问题