class A
{
public:
A(){m_a = 1; m_b = 2;}
~A(){};
void fun(){printf("%d%d",m_a,m_b);}
public:
int m_a;
int m_b;
};
class B
{
public:
B(){m_c = 3;}
~B();
void fun(){printf("%d",m_c);}
public:
int m_c;
};
int tmain(void)
{
A a;
B *pb = (B*)(&a);
cout << &a << endl; //0x22ff58
cout << &(a.m_a) << endl; //print the address of the a.m_a 0x22ff58
printf("%p\n",&A::m_a); //print the offset from m_a to the beginning A object
//address 00000000
printf("%p\n",&A::m_b); //print the offset from m_a to the beginning A object
//address 00000004
printf("%p\n",&B::m_cn); //print the offset from m_c to the beginning B object
//address 00000000
system("PAUSE");
return 0;
}
class A
{
public:
A(){m_a = 1; m_b = 2;}
~A(){};
void fun(){printf("%d%d",m_a,m_b);}
public:
int m_a;
int m_b;
};
class B
{
public:
B(){m_c = 3;}
~B();
void fun(){printf("%d",m_c);}
public:
int m_c;
};
int tmain(void)
{
A a;
B *pb = (B*)(&a);
cout << &a << endl; //0x22ff58
cout << &(a.m_a) << endl; //print the address of the a.m_a 0x22ff58
printf("%p\n",&A::m_a); //print the offset from m_a to the beginning A object
//address 00000000
printf("%p\n",&A::m_b); //print the offset from m_a to the beginning A object
//address 00000004
printf("%p\n",&B::m_cn); //print the offset from m_c to the beginning B object
//address 00000000
system("PAUSE");
return 0;
}
class A
{
public:
A(){m_a = 1; m_b = 2;}
~A(){};
void fun(){printf("%d%d",m_a,m_b);}
public:
int m_a;
int m_b;
};
class B
{
public:
B(){m_c = 3;}
~B();
void fun(){printf("%d",m_c);}
public:
int m_c;
};
int tmain(void)
{
A a;
B *pb = (B*)(&a);
cout << &a << endl; //0x22ff58
cout << &(a.m_a) << endl; //print the address of the a.m_a 0x22ff58
printf("%p\n",&A::m_a); //print the offset from m_a to the beginning A object
//address 00000000
printf("%p\n",&A::m_b); //print the offset from m_a to the beginning A object
//address 00000004
printf("%p\n",&B::m_cn); //print the offset from m_c to the beginning B object
//address 00000000
system("PAUSE");
return 0;
}