我有以下结构:
struct type1 {
struct type2 *node;
union element {
struct type3 *e;
int val;
};
};
初始化指针时*f
指向一个实例type1
并做类似的事情:f.element->e
甚至只是f.element
,我得到:
error: request for member ‘element’ in something not a structure or union
我在这里监视什么?
element
是工会的名称,而不是成员的名称type1
。你必须给予union element
a name:
struct type1 {
struct type2 *node;
union element {
struct type3 *e;
int val;
} x;
};
然后你可以通过以下方式访问它:
struct type1 *f;
f->x.e
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)