void*使用中偏移的问题
程序如下:
#include <iostream>
using namespace std;
class A
{
public:
virtual ~A(){};
private:
int a;
};
class B
{
public:
virtual ~B(){};
private:
int b;
};
class C:public A,public B
{
private:
int c;
};
main()
{
C *pc=new C;
void *pd=pc;
B *p1=(B *)pd;
B *p2=(B *)pc;
cout<<int(pc)<<endl;
cout<<int(p1)<<endl;
cout<<int(p2)<<endl;
cout<<(int(p1)-int(pc))<<endl;
cout<<(int(p2)-int(pc))<<endl;
delete pd;
return 0;
}
为什么最后结果是0和8,偏移在哪里发生的,求解哈