知道这是有效的 c++11
int i {1};
这个有效吗?
int j[] {{1}};
GCC 给出错误,发出警告。
最佳答案
这是无效的,因为 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
}
关于c++ - 聚合内标量的大括号初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910056/