c++ - 接受 std::array 的复制构造函数中的初始值设定项列表

标签 c++ intellisense visual-studio-2013

#include <array>
#include <algorithm>

template<typename Type, unsigned int ArraySize>
class Vector
{
public:
    std::array<Type, ArraySize> arr;
    Vector(){ std::fill(arr.begin(), arr.end(), 0); }
    Vector(const std::array<Type, ArraySize>& input) : arr(input){}
};

#include <iostream>

int main()
{
    Vector<double, 4> a2{{1, 2, 3, 4}}; 
    std::cout << a2.arr[0];
    std::cout << a2.arr[1];
    std::cout << a2.arr[2];
    std::cout << a2.arr[3];
}

此代码在调试和 Release模式下的 Visual Studio 2013 中符合良好要求,但在编译时 IntelliSense 给出此错误:

IntelliSense: no instance of constructor "CHL::Vector::Vector [with Type=double, ArraySize=4U]" matches the argument list argument types are: ({...})

我的问题是这是 C++ 中的有效代码吗?如果是的话,我怎样才能阻止 IntelliSense 用这个错误污染我的错误列表。

最佳答案

Intellisense 需要三对大括号:

class Vector {
    Vector( //1 for initialization of vector
        std::array<...> //1 for initialization and 1 for internal array
    );
};

但是,该语言允许省略大括号,这意味着只需两个即可。我不确定为什么编译器会捕获到这一点,而 Intellisense 不会,但如果您使用 CTP,可能会像上次一样,直到真正发布时,编译器更改才反射(reflect)在 Intellisense 中。

关于c++ - 接受 std::array 的复制构造函数中的初始值设定项列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20171518/

相关文章:

c++ - 关于光标更改的通知

razor - Visual Studio 2012 中缺少 Intellisense

ruby-on-rails - 使 Vim 的全能上下文感知 ruby​​/rails 的最佳方法是什么? (即智能感知)

visual-studio - 无法连接已配置的开发 Web 服务器 Visual Studio 2013

c++ - 如何摆脱 GCC 中的 `deprecated conversion from string constant to ‘char*’ `警告

c++ - 如何在 C++ 中更改 Latin1-UTF8 编码(可能使用 Boost)?

flutter - 自动完成/智能感知不适用于VSCode中的 Dart/flutter

windows-phone-8 - Windows Phone 8.1 应用程序无法在模拟器中运行

android - 使用 Xamarin 在 Visual Studio 2013 中缺少 Android 3.1 SDK

c++ - 如何在 C++ 中检测 tcp 客户端连接到服务器