我使用开源代码在类中声明静态联合。
VAD.h
:
class VD
{
public:
static union Wu
{
const short w[2 * 64];
const double y[16];
} wu;
};
VAD.cpp
:
VD:: Wu VD:: wu =
{
0x0000, 0x7FFF, 0x0000, 0x7FFF, 0x0000, 0x7FFF, 0x0C8B, 0x7F61,
0x18F8, 0x7D89, 0x2527, 0x7A7C, 0x18F8, 0x7D89, 0x30FB, 0x7641,
0x471C, 0x6A6D, 0x2527, 0x7A7C, 0x471C, 0x6A6D, 0x62F1, 0x5133,
0x30FB, 0x7641, 0x5A82, 0x5A82, 0x7641, 0x30FB, 0x3C56, 0x70E2,
0x6A6D, 0x471C, 0x7F61, 0x0C8B, 0x471C, 0x6A6D, 0x7641, 0x30FB,
0x7D89, -0x18F8, 0x5133, 0x62F1, 0x7D89, 0x18F8, 0x70E2, -0x3C56,
0x5A82, 0x5A82, 0x7FFF, 0x0000, 0x5A82, -0x5A82, 0x62F1, 0x5133,
0x7D89, -0x18F8, 0x3C56, -0x70E2, 0x6A6D, 0x471C, 0x7641, -0x30FB,
0x18F8, -0x7D89, 0x70E2, 0x3C56, 0x6A6D, -0x471C, -0x0C8B, -0x7F61,
0x7641, 0x30FB, 0x5A82, -0x5A82, -0x30FB, -0x7641, 0x7A7C, 0x2527,
0x471C, -0x6A6D, -0x5133, -0x62F1, 0x7D89, 0x18F8, 0x30FB, -0x7641,
-0x6A6D, -0x471C, 0x7F61, 0x0C8B, 0x18F8, -0x7D89, -0x7A7C, -0x2527,
0x0000, 0x7FFF, 0x0000, 0x7FFF, 0x0000, 0x7FFF, 0x30FB, 0x7641,
0x5A82, 0x5A82, 0x7641, 0x30FB, 0x5A82, 0x5A82, 0x7FFF, 0x0000,
0x5A82, -0x5A82, 0x7641, 0x30FB, 0x5A82, -0x5A82, -0x30FB, -0x7641
};
当我在Windows上使用VC ++ 6.0编译此代码时出现此错误:
public:static union VD :: Wu VD :: wu':无法使用初始化列表初始化非聚合
任何人都可以帮助我吗?
答案 0 :(得分:4)
你需要一对额外的花括号,因为你想要初始化嵌套在联合中的数组:
VD:: Wu VD:: wu =
{
{ // <-- forgot
<snip />
} // <-- these
};