4

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,  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
};

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?

1

1 Answer 1

4

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
};
Sign up to request clarification or add additional context in comments.

1 Comment

@user: Strange, both versions work for me on VS2010, so I think your Visual Studio is just way too old. :|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.