开发者

Initialize static union within class

I use open-source code that declared static union inside class like this.

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,  0开发者_StackOverflowx7641,  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
};

when I compiled this code using VC++ 6.0 on windows..this error occured:

public: static union VD::Wu VD::wu' : non-aggregates cannot be initialized with initializer list

anyone can help me please?


You need an extra pair of curly braces, as you want to initialize the array that is nested inside the union:

VD:: Wu  VD:: wu =
{
  { // <-- forgot
    <snip />
  } // <-- these
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜