2

Why I get error :too many initializers for ‘Array’ Its C++11 code and I dont know where is problem

#include <iostream>
using namespace std;

struct Point {
int x,y ;
};
Point points[3] {{1,2},{3,4},{5,6}};
int x2 = points[2].x;

struct Array {
Point elem[3];
};

int main() {
    cout << "!!!\nStructure!!!" << endl; //

    Array points2  {{1,2},{3,4},{5,6}};// *too many initializers for‘Array’* 
    int y2 = points2.elem[2].y;

    cout << "!!!here points2 = !!!" << y2 <<endl;

    return 0;
}
1
  • Array points2 {{{1,2},{3,4},{5,6}}}; SOLVED Commented Jan 21, 2015 at 13:18

1 Answer 1

8

You actually need one more set of braces to initialize that struct

Array points2  {{{1,2},{3,4},{5,6}}};
//               ^Point
//              ^Point[]
//             ^Array

Working example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.