I'm trying to initialize a nested structure array.
Here is what I am doing:
// init a nested struct
struct L1 {
struct L2 {
int i[4];
} l2[3];
};
L1::L2 l2 = {1,2,3,4};
L1::L2 l2_a[] = { {1,2,3}, {1,2}, {1,2,3,4}};
L1 l1 = {
{{1,2,3}, {1,2}, {1,2,3,4}}
};
L1 l1_a0 = {};
L1 l1_a1 = {0};
L1 l1_a[] = {
{{1,2,3}, {1,2}, {1,2,3,4}},
{{1,2,3}, {1,2}, {1,2,3,4}}
}; // ... error: too many initializers for 'L1'
According to what happens correct above, I would expect the the last line derived (initializing the array of nested struct) to be right, but to my surprise, the compiler doesn't like it.
Can it be done at all? Here's a related post about initializing nested structs. Btw, I'm using g++.