c++ 11 std数组-gcc和visual studio之间的区别

标签 c++ arrays c++11 std

这部分代码有问题:

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/

相关文章:

c++ - opencv Apple Mach-O 链接器

sql - postgresql:选择返回数组

c++ - 将结构传递给头文件的标准方法

c++ - "Link executables with xxx.lib"是什么意思

java - 数组中的值未正确更改

ios - 点击 UITableViewCell 时数组索引超出范围,无论是否使用 didselectrowatindex 方法

c++ - 返回字节数组或将数组传递给函数

c++ - 可变参数模板问题

c++ - 在 C++11 中构建 union 元组

c++ - C++线程中的段错误