In C++ the size of an array is part of its type.* There's a special rule that allows an array declaration to deduce its size from the initializer, so you don't always have to write the type explicitly.
You can also write and use incomplete types in certain circumstances, but you can't do anything with them that requires a complete type.
So the problem here is that you're writing an incomplete type and doing something with it that requires a complete type (namely, declaring an object of that type). Adding an initializer is one way to declare the array's size and thus complete the type, which avoids the error.
If what you really want is to say "and the last field is a collection of ints," then you need to use a type that can represent that (again, arrays have a fixed number of elements). In C++ the most obvious solution is std::vector<int>
. Using std::vector
you can write your pseudo-code almost exactly:
oTACent.colRatios = {1, 1, 2};
Another option, which you might see but shouldn't write, is to use a pointer. C++ is defined such that you can use a pointer to an element of array similarly to an array. Since a pointer type doesn't include the array size, the same pointer type can be used with an array of any size.
* some compilers support variable length array members as an extension, where the size of the array is determined when the struct is initialized, but this isn't standard C++ and it still requires the size to be known at initialization (rather than from a later assignment, like in your pseudo code where you assign to the array). There's another extension called 'flexible arrays' where the last member can be declared without a size and then you manually allocate enough memory for the entire struct plus however large you want the array to be.