我有这段代码:
#include <array>
int main(int, char **argv)
{
std::array<int, 3> a = {1,2,3};
}
这编译很好(-std = c ++ 11),但是如果你包含-Wall它会发出我不明白的警告:
clang_pp_error.cpp:5:28: warning: suggest braces around initialization of subobject [-Wmissing-braces]
std::array<int, 3> a = {1,2,3};
^~~~~
{ }
答案 0 :(得分:18)
改为使用std::array<int, 3> a = {{1,2,3}};
。
请参阅 Why wasn't a double curly braces syntax preferred for constructors taking a std::initializer_list
答案 1 :(得分:16)