c++11 STD数组- GCC与visual studio的区别

c++11 std array - differences between gcc and visual studio

本文关键字:visual studio 区别 GCC STD 数组 c++11      更新时间:2023-10-16

我对这部分代码有一个问题:

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.0VCINCLUDEarray(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有一些困难,如果你想要一个列表,看这里。