A while ago I wrote code resembling this:
struct Thing
{
int a,b;
};
struct Junk
{
double x;
Thing things[10];
};
Junk myjunk[] =
{
{ 23.4, { {10,20}, {30,40} } },
{ 45.6, { {55,66}, {77,88} } }
};
Originally Thing had no constructors - just a flat simple struct to hold a couple integers. myjunk[] is meant to be special hand-written data to feed into something. In real life it has dozens of lines not just two. This code compiled fine.
Then this morning I added constructors to Thing, useful elsewhere in the great scheme of things, for example, to call functions like blarf(Thing(123,456)); and create huge arrays on the heap with 'new'.
struct Thing
{
int a,b;
Thing();
Thing(int _a, int _b);
};
Now it doesn't compile. I get
Error 1 error C2552: 'Junk::things' : non-aggregates cannot be initialized with initializer list
Yes, class with constructors cannot be made this way. What is the quickest simplest fix to get this compiling?
I know C++11 allows some new ways to initialize variables, but it's not clear in this case what's best. I'm not creating a lone Thing, but an array, and that within another struct. 'Junk' will never have a constructor.
Note that there aren't any virtual methods anywhere, and never will be for Thing and Junk. I'm using Visual Studio 2010, and not sure if it's taking source to be C++11 or older C++.