What would be the best way to do default initialization for this struct in a header file in C++14?
struct ValueStruct
{
int m_Number;
double m_arrValues[10];
};
1: Brace initialization
struct ValueStruct
{
int m_Number= -1;
double m_arrValues[10] = { -1, -1 ...... -1 };
};
2: I create a constructor and then initialize everything there. By using a for loop for array.
It depends on your needs. If you only need to initialize the array, you can use the brace initialization, which will also be easier to read. The constructor however brings in more flexibility if you need to do more actions during the initialization of your struct. It will also be more useful and easier to use a constructor if your array gets bigger, which will make the brace initialization a bit more difficult and repetitive.