c++:vtable 是否包含指向非虚函数的指针? [英] c++: Does a vtable contains pointers to non-virtual functions?

查看:43
本文介绍了c++:vtable 是否包含指向非虚函数的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vtable 包含指向该类的虚函数的指针.它还包含指向非虚函数的指针吗?

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

谢谢!

推荐答案

这是一个实现细节,但不是.如果实现将指向非虚函数的指针放入 vtable 中,则不能使用这些指针进行函数调用,因为这通常会导致调用不正确的非虚函数.

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.

当调用非虚拟函数时,实现必须使用调用该函数的对象的静态类型来确定要调用的正确函数.存储在 vptr 访问的 vtable 中的函数将依赖于对象的动态类型,而不是访问它的引用或指针的任何静态类型.

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.

这篇关于c++:vtable 是否包含指向非虚函数的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆