vtable 是 virtual table(虚函数表) 的简称:在 C++ 等支持多态的语言实现中,编译器通常为含有虚函数的类生成的一张“函数指针表”,用于在运行时根据对象的实际类型进行动态派发(dynamic dispatch)。不同编译器实现细节可能不同,但概念常见。
/ˈviːˌteɪbəl/
The vtable lets the program call the right virtual function at runtime.
vtable 让程序能在运行时调用正确的虚函数。
When a base-class pointer refers to a derived object, the vtable lookup ensures the overridden method is dispatched correctly, which is essential for polymorphism but can add a small runtime cost.
当基类指针指向派生类对象时,vtable 的查找机制能确保被重写的方法被正确派发,这对多态很关键,但可能带来少量运行时开销。
vtable 来自 virtual table 的缩写:v- 表示 virtual(虚的/虚函数的),table 表示“表格/表”。它并非标准里必须出现的术语,更像是业界对“虚函数表”这一实现机制的通用叫法。