在编译时出现error: types cannot be declared in an anonymous union,解决方法是把对结构的声明放union外面。
源码如下:
struct test {
int a;
int b;
union {
struct stu {
int a;
int b;
}stu;
struct stu1 {
int a;
int b;
}stu1;
struct stu2 {
int a;
int b;
}stu2;
}
};
修改为:
struct stu {
int a;
int b;
};
struct stu1 {
int a;
int b;
};
struct stu2 {
int a;
int b;
}stu2;
struct test {
int a;
int b;
union {
struct stu stu;
struct stu1 stu1;
struct stu2 stu2;
}
};