这部分代码有问题:
typedef std::array<u32, 3> my_array;
void foo()
{
my_array a1{{1, 2, 3}};
a1 = {{1, 2, 3}}; // PROBLEM - does not work;
my_array a2{{3, 2, 1}};
a1 = a2;
}
GCC 4.7 也编译此代码,但 Visual Studio with cl 从 2012 年 11 月开始失败:
error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'initializer-list' (or there is no acceptable
conversion) 1> C:\Program Files (x86)\Microsoft Visual Studio
11.0\VC\INCLUDE\array(211): could be 'std::array<u32,3> &std::array<u32,3>::operator =(const std::array<u32,3> &)' 1>
while trying to match the argument list '(my_array, initializer-list)'
此语法是否正确并符合 c++11 标准?我找不到任何关于此的信息,也不知道我应该责怪哪个编译器。在此先感谢您的帮助。
最好的问候。
最佳答案
正如我所说,VS2012
有点蹩脚并且在 C++11
上有一些困难,如果你想要一个列表,请查看 here .
关于c++ 11 std数组-gcc和visual studio之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16168987/