64,662
社区成员
发帖
与我相关
我的任务
分享
# include<iostream>
using namespace std;
#define BASE_DATA int fd;int type;
struct parent
{
BASE_DATA
};
struct child1
{
BASE_DATA
int c1;//data of child1;
};
struct child2
{
BASE_DATA
int c2;//data of child2;
};
int main()
{
struct child1 a = {1,1,2};
struct child2 b = {1,2,3};
struct parent *p = (struct parent *)&a; //这里改了下
//struct parent *p = (struct child2*)&b;
if (p->type == 1)
{
cout << p->fd<< endl;
}
else if (p->type == 2)
{
//cout << p->c2 << endl;
cout << p->fd << endl;
}
return 0;
}