我对这部分代码有疑问:
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也可以编译此代码,但是从2012年11月起带有cl的Visual Studio失败,原因是:
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
有点me脚,并且在C++11
上有一些困难,如果您想要一个列表,请查看here。