相关疑难解决方法(0)

空的虚拟表可以存在吗?

#include <iostream>
using namespace std;

class Z
{
public:
    int a;
    virtual void x () {}
};

class Y : public Z
{
public:
    int a;
};

int main() 
{
    cout << "\nZ: "  << sizeof (Z);
    cout << "\nY: "  << sizeof (Y);
} 
Run Code Online (Sandbox Code Playgroud)

因为Y继承了Z,所以也会有虚表。美好的。但是,它没有任何虚函数,那么 Y 的虚表的内容是什么?
会空吗?

c++ virtual vtable

3
推荐指数
1
解决办法
628
查看次数

标签 统计

c++ ×1

virtual ×1

vtable ×1