基类有虚函数,子类无虚函数,也会创建新的虚函数表

 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 }
  • 结论:即使子类中没有重写或定义新的虚函数,仍然会建立新的虚函数表,不会使用父类的虚函数表
posted @ 2021-10-01 10:50  m0_46427273  阅读(237)  评论(0)    收藏  举报