我迫切需要找到以下问题的解决方案:...与构造不允许在工会问题
namespace test
{
template <int param = 0> struct Flags
{
int _flags;
Flags()
{
_flags = 0;
}
Flags(int flags)
{
_flags = flags;
}
void init()
{
}
};
union example
{
struct
{
union
{
struct
{
Flags<4096> f;
}p1; //error: member 'test::example::<anonymous struct>::<anonymous union>::<anonymous struct> test::example::<anonymous struct>::<anonymous union>::p1' with constructor not allowed in union
struct
{
Flags<16384> ff;
}p2; //error: member 'test::example::<anonymous struct>::<anonymous union>::<anonymous struct> test::example::<anonymous struct>::<anonymous union>::p2' with constructor not allowed in union
}parts;
byte bytes[8];
}data;
int data1;
int data2;
}
}
这是令人沮丧,如果我添加标签,以P1和P2结构,代码将编译,但F & FF成员将无法访问:
...
struct p1
{
Flags<4096> f;
};
struct p2
{
Flags<4096> ff;
};
...
void test()
{
example ex;
ex.data.bytes[0] = 0; //Ok
ex.data.parts.p1.f.init(); //error: invalid use of 'struct test::example::<anonymous struct>::<anonymous union>::p1'
}
有什么办法,使这项工作不知何故?
非常感谢,伙计们! – Ryan 2011-05-16 08:43:05