什么是C ++中的Vtable [英] What is Vtable in C++
问题描述
可能重复:
为什么需要虚拟表?
什么vtAble在C ++中是吗?
要知道vtable是一个虚拟表,其中包含指向虚拟函数的指针数组。是否有实用的文章? (任何演练都会受到赞赏)
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)
推荐答案
V表(或虚拟表)是大多数C ++实现实现多态性的方式。对于类的每个具体实现,都有一个指向所有虚拟方法的函数指针表。指向该表的指针(称为虚拟表)作为所有对象中的数据成员存在。当调用虚拟方法时,我们将查找对象的v表并调用适当的派生类方法。
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.
这篇关于什么是C ++中的Vtable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!