Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
知道这是有效的 c++11
int i {1};
这个有效吗?
int j[] {{1}};
GCC 给出一个错误,发出警告。
这是无效的,因为它是一个(标量)j数组。int您只能对本身是聚合的成员使用嵌入式大括号。
j
int
#include <initializer_list> struct T { int x, y; }; int main() { int j[] {{1}}; // error, int is scalar T t[] {{1,2}}; // OK, T is aggregate }