0

In this struct I want to initialize an array but Visual Studio marks an error right after rulesRefIndex[3]

expected a ';'

struct Fact{
    char name[4];
    char value[6];
    int rulesRefIndex[3] = { -1 };
};

Error occurs even with int rulesRefIndex[3] = { -1,-1,-1 }; and int rulesRefIndex[3] = {[0...3]= -1 }; as stated here.

What am I doing wrong?

Community
  • 1
  • 1
Mike
  • 809
  • 6
  • 20

1 Answers1

1

You can initialize only when defining a variable, not when defining a structure(datatype) in c. Check the following post for details.

Why can't we initialize members inside a structure?

Moreover your question is related to partial initialization. Please check this post.

C and C++ : Partial initialization of automatic structure

Community
  • 1
  • 1
Umamahesh P
  • 1,224
  • 10
  • 14