C++中的Vtable是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3554909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 13:06:35  来源:igfitidea点击:

What is Vtable in C++

c++vtable

提问by Simsons

Possible Duplicate:
why do I need virtual table?

可能的重复:
为什么我需要虚拟表?

What is vtAble in C++?
Got to know vtable is a virtual table which has an array of pointers to virtual functions. Is there an article with practical implementation? (Any walk through will be appreciated)

C++ 中的 vtAble 是什么?
知道 vtable 是一个虚拟表,它有一个指向虚拟函数的指针数组。有没有实际操作的文章?(任何走过将不胜感激)

回答by doron

V-tables (or virtual tables) are how most C++ implementations do polymorphism. For each concrete implementation of a class, there is a table of function pointers to all the virtual methods. A pointer to this table (called the virtual table) exists as a data member in all the objects. When one calls a virtual method, we lookup the object's v-table and call the appropriate derived class method.

V 表(或虚拟表)是大多数 C++ 实现进行多态的方式。对于类的每个具体实现,都有一个指向所有虚拟方法的函数指针表。指向该表(称为虚拟表)的指针作为所有对象中的数据成员存在。当调用虚拟方法时,我们查找对象的 v-table 并调用适当的派生类方法。

回答by phadej

vTable (virtual table) is an implementation detail of dynamic dispatch (virtualmethods).

vTable(虚拟表)是动态调度(virtual方法)的一个实现细节。

See C++-Lite-Faqfor more details.

有关更多详细信息,请参阅C++-Lite-Faq

回答by Chubsdad

For all it's worth, it is not a standard C++ terminology. It is just an implementation detail used by the implementation to implement virtual functions/dynamic binding

尽管如此,它并不是标准的 C++ 术语。它只是实现用来实现虚函数/动态绑定的一个实现细节