Error: type name is not allowed in C++

前端 未结 1 475
一整个雨季
一整个雨季 2021-01-24 00:24

When I compiled my code, VC++ returns an error, as stated above. The affected line is (brushes){5.6, 214.0 , 13.0}

More specifically, here is the affected c

相关标签:
1条回答
  • 2021-01-24 01:06

    You are using a C99 construct (§6.5.2.5 Compound Literals) which is not supported by MS VC, but which is supported by GCC.

    You should be able to get the code to compile on both by dropping the (brushes) notation:

    const  brushes palette[] = {
        { {   5.6, 214.0, 13.0 } },
        { { 200.0, 211.0, 12.0 } },
    };
    

    This will initialize the first member of the union that is brushes. This works with GCC; it should work with MSVC too, I believe.

    0 讨论(0)
提交回复
热议问题