- #include <iostream>
- using namespace std;
- class Empty
- {};
- class Derived : virtual public Empty
- {
- char c;
- };
- int main()
- {
- cout << "sizeof(Empty) " << sizeof(Empty) << endl;
- cout << "sizeof(Derived) " << sizeof(Derived) << endl;
- return 0;
- }
为什么尺寸即将到来8我觉得它应该是9,
如果我将’c’声明为整数,那么它也是8
你请给我解释逻辑
解决方法
大小取决于实现,它取决于特定编译器实现如何实现虚拟主义&填充.你不应该期望具体的价值是某种东西.如果你想计算程序中的大小,只需使用sizeof即可.