代码之家  ›  专栏  ›  技术社区  ›  user32434999

std::用visualstudio2010初始化数组

  •  0
  • user32434999  · 技术社区  · 6 年前

    使用VisualStudio2010初始化std::数组时遇到问题。我知道用一个现代的编译器我可以做以下的事情

    #include <array>
    
    class A
    {
        A() : arr({1,2,3,4,5,6}) {}
    public:
    std::array<float, 6> arr;
    };
    

    但是,VisualStudio2010不允许这样做(因为它不完全支持 C++11

    1 回复  |  直到 6 年前
        1
  •  4
  •   Bathsheba    6 年前

    可惜没有。 聚合初始化 是C++ 11概念和Visual Studio 2010实现C++ 03标准。

    如果你需要能够创造 const A ,然后在 static arr .