直接使用初始化列表初始化只有一个数组作为成员的结构是否合法?

Is it legal to initialize a struct with only one array as member using a initializer list directly?

#include <iostream>

class vec
{
public:
    int  arr[2];
};


int main()
{
    vec a = { { 1,2 } };// works 
    vec b = { 1,2 };// works too ,but why ?
    std::cin.get();
}

vec 除了默认构造函数外没有其他构造函数。

但是这段代码编译通过了,不知道为什么。

http://ideone.com/uyx98o

Aggregate initialization 太棒了,你甚至不需要获得嵌套权就可以让它工作,而且你还可以提供比成员更少的值:

#include <iostream>
#include <string>

struct A {
    struct { int a; std::string b[3]; } a;
    double b, c;
};

int main() {
    A a = { 10, "a", "b", "c", 3.1415 };
    std::cout << a.a.a << " " << a.a.b[0] << " " << a.a.b[2]
              << " " << a.b << " " << a.c;
}

Live