class CFoo{
public:
int iBar1;
int iBar2;
int iBar3;
};
void main()
{
CFoo* pClass = NULL;//此处不需要new一个CFoo对象实例(只读不写)
int iFldKey1 = (long)(&(pClass->iBar1)) - (long)(pClass);
int iFldKey2 = (long)(&(pClass->iBar2)) - (long)(pClass);
int iFldKey3 = (long)(&(pClass->iBar3)) - (long)(pClass);
cout << "iFldKey1 : " << iFldKey1 << ", iFldKey2 : " << iFldKey2 << ", iFldKey3 : " << iFldKey3 << endl;
}
/*
运行结果:
iFldKey1 : 0, iFldKey2 : 4, iFldKey3 : 8
*/