I have implemented following structures:
struct Point {
int x,y;
};
struct Array {
Point elem[3];
};
Could you explain why I'm getting an error:
error: too many initializers for 'Array'
when I use following construction?:
Array points2 {{1,2},{3,4},{5,6}};
You need more braces, since you're initialising objects within an array within a class:
Array points2 { { {1,2},{3,4},{5,6}}};
^ ^ ^
| | |
| | array element
| array
class
You actually need one more set of braces like so:
Array points2 {{{1,2},{3,4},{5,6}}};
Working example
See this post for further explanation of when these extra braces are required. It is related to whether the container is an aggregate or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With