Search code examples
c++visual-studio-2017

C++ C2100 Illegal Indirection on initialize struct variable


I'm using "VS2017 Community", platform Windows 7. And I got an error C2100 when tried to do next:

struct Conf {
    unsigned int id;
    int test1;
    int test2;
    int test3;
    int test4;
    int test5;
    int test6;
};

Conf cf({
    0,
    0,
    0,
    0,
    0,
    0,
    0
}); //<-- Here is error - C2100 Illegal Indirection

Can anyone tell me what is possible the problem here? Thanks.


Solution

  • This struct has no constructor. The code you want is the following:

    struct Conf {
        unsigned int id;
        int test1;
        int test2;
        int test3;
        int test4;
        int test5;
        int test6;
    };
    
    Conf cf = {
        0,
        0,
        0,
        0,
        0,
        0,
        0
    }; // Array initializer for struct type.