基类有虚函数,子类无虚函数,也会创建新的虚函数表
1 class Base 2 { 3 virtual void show() 4 { 5 cout << "Base" << endl; 6 } 7 }; 8 class Derived : public Base 9 { 10 11 }; 12 int main() 13 { 14 typedef void(*Func)(); 15 Base b; 16 Derived d; 17 cout << *(int**)&b << endl; //输出:00A69B34 18 cout << *(int**)&d << endl; //输出:00A69B48 19 }
- 结论:即使子类中没有重写或定义新的虚函数,仍然会建立新的虚函数表,不会使用父类的虚函数表

浙公网安备 33010602011771号