假设有如下这样一个类:
class X { public: void xoo(){} };
请问sizeof(X)的值为多少?
#include <iostream> using namespace std; class A { }; class B { char ch; void func() {} }; class C { char ch1; //占用1字节 char ch2; //占用1字节 virtual void func() {} }; class D { int in; virtual void func() {} }; int main() { A a; B b; C c; D d; cout << sizeof(a) << endl;//result=1 cout << sizeof(b) << endl;//result=1 cout << sizeof(c) << endl;//result=8 cout << sizeof(d) << endl;//result=8 }