VC++中类对象的首地址怎么输出?百思不得其解!求高手赐教
#include<stdio.h>
class A
{
public:
unsigned short m_a1;
unsigned short m_a2;
A()
{m_a1=10;m_a2=20;}
void fun()
{printf("%u,%u\n",m_a1,m_a2);}
};
class B
{
public:
unsigned long m_a3;
B(){m_a3=30;}
void fun(){printf("%x\n",m_a3);}
};
int main()
{
A a;
B *pb;
pb=(B*)(&a);
pb->fun();
return 0;
}
运行结果为:14000a
pb=(B*)(&a);把a首地址的值赋给PB
而pb指向的变量是m_a3
所以m_a3的内容为a首地址
感觉应该是30,可是最后运行结果为14000a
求高手指点迷津!!!!