63,593
社区成员




#include <iostream>
#define offsert(type,m_mem) (unsigned long)(&(((type*)0)->m_mem))
class B{
public:
bool m_bTemp;
int m_nTemp;
bool m_bTemp2;
};
class C{
public:
int m_nTemp;
bool m_bTemp;
bool m_bTemp2;
};
using namespace std;
int main(int argc, char** argv){
cout<< sizeof(B) <<endl;
cout<< sizeof(C) <<endl;
cout<< "类B的个成员的内存结构:\n";
cout<< "member\t\taddress offsert\n";
cout<< "bool m_bTemp\t\t" << offsert(B, m_bTemp) << endl;
cout<< "int m_nTemp\t\t" << offsert(B, m_nTemp) << endl;
cout<< "bool m_bTemp2\t\t" << offsert(B, m_bTemp2) << endl;
cout<< "类C的个成员的内存结构:\n";
cout<< "member\t\taddress offsert\n";
cout<< "int m_bTemp\t\t" << offsert(C, m_nTemp) << endl;
cout<< "bool m_nTemp\t\t" << offsert(C, m_bTemp) << endl;
cout<< "bool m_bTemp2\t\t" << offsert(C, m_bTemp2) << endl;
}
¦bool¦----¦----¦----¦
¦-------int---------¦
¦bool¦----¦----¦----¦
¦-------int---------¦
¦bool¦bool¦----¦----¦