0

I have a struct, that looks something like

struct MyStruct {
    static const std::vector<CustomStruct> someConstValues;
};

const std::vector<CustomStruct> MyStruct::someConstValues = {
    CustomStruct(0),
    CustomStruct(1)
};

The definition of the static member takes place outside of the struct since otherwise i get error: in-class initialization of static data member 'const std::vector<CustomStruct> MyStruct::someConstValues' of non-literal type.

But in the example above i get multiple definition of 'MyStruct::someConstValues' ... first defined here.

How i can i tell the compiler to accept my static const std::vector<CustomStruct>?

T. Grumser
  • 99
  • 3
  • 18
  • 1
    Please provide a proper [mre], this is missing too much information. My best guess is that you put both the declaration and definition into a header file, which is included in multiple other files? – UnholySheep Mar 10 '22 at 13:07
  • Yes i included the definition in the header file. That solves my problem thank you, – T. Grumser Mar 10 '22 at 13:08

0 Answers0