I've been tasked to remove some compiler warning. I've been able to boil the problem down to the following example, which I am scratching my head why it won't work. I guess I don't know how to initialize stuff in C++. Any help would be appreciated.
I use g++ like so: g++ init_arr.cpp
Here's the code. I want to initialize all the people at all the tables in Aisle pizza:
// init_arr.cpp
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct Person {
int id;
string name;
double money;
};
struct Table {
Person tab[4];
};
struct Aisle {
Table ais[3];
};
int main() {
cout << "main function()" << endl;
Aisle pizza =
{
{ // Table 0
{ 0, "Tom", 100.0 },
{ 1, "Mary", 101.0 },
{ 2, "Jane", 103.0 },
{ 3, "Joe", 104.0 }
},
{ // Table 1
{ 0, "Tom", 100.0 },
{ 1, "Mary", 101.0 },
{ 2, "Jane", 103.0 },
{ 3, "Joe", 104.0 }
},
{ // Table 2
{ 0, "Tom", 100.0 },
{ 1, "Mary", 101.0 },
{ 2, "Jane", 103.0 },
{ 3, "Joe", 104.0 }
}
};
return 0;
}
I thought the above would work, but I get the following error:
g++ init_arr.cpp -std=gnu++0x
init_arr.cpp: In function ‘int main()’:
init_arr.cpp:49: error: too many initializers for ‘Table [3]’
init_arr.cpp:49: error: too many initializers for ‘Aisle’