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

后端 未结 4 1313
走了就别回头了
走了就别回头了 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: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.

提交回复
热议问题