Given the following code:
struct BufferPair
{
ByteBuffer _a;
ByteBuffer _b;
bool _c;
};
struct TestData
{
MyClass _myClass;
BufferPair _data[];
};
I’m trying to initialize an array of TestData where I also initialize an array of BufferPair. Each instance of TestData will have a differently sized BufferPair array. Simplified Example:
const TestData g_Data[] = { MyClass(), { { bufOne, bufTwo, someBool }, { bufThree, bufFour, anotherBool } } };
While trying this, I get the following gcc error:
error: too many initializers for 'BufferPair [0]'.
How would I solve this? Thanks.
_datain the code above is not a complete type (it is lacking the size of the array), and you are not allowed to declare a member to be of incomplete type in the C++ standard:This seems to compile as an extension to the language in gcc. Now it still fails to compile the definition of the variable as the array has no size and you are trying to initialize members in it.