65,210
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
using namespace std;
struct A{
virtual int fun(); //4 byte
char x; //1 byte
};
struct B:public A{
short myfun(); //2 byte
union{
unsigned short m;
unsigned int c;
}xx; //4 byte
int (__stdcall *funs)(); //4 byte
};
union{
unsigned short m;
unsigned int c;
}xx;
short myfun();
int (__stdcall *funs)(); //4 byte
struct C{
short myfun(); //2 byte
union{
unsigned short m;
unsigned int c;
}xx; //4 byte
int (__stdcall *funs)(); //4 byte
};
int main()
{
cout << sizeof(myfun()) << endl;//2
cout << sizeof(( *funs)()) << endl;//4
cout << sizeof(xx) << endl;//4
cout << sizeof(A) << endl;//8
cout << sizeof(B) << endl;//16
cout << sizeof(C) << endl;//8
cout<<endl;
cout<<offsetof( B , x )<<endl;
cout<<offsetof( B , xx )<<endl;
cout<<offsetof( B , funs )<<endl;
return 0;
}