结构和数组(“数组”的初始值设定项太多)C++

Structures and Arrays (too many initializers for ‘Array’ ) C++

为什么我会收到错误消息:“Array”的初始值设定项太多 它的 C++11 代码,我不知道问题在哪里

#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;
}

您实际上还需要一组大括号来初始化 struct

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

Working example