复制构造中接受 std::array 的初始器列表
Initilizer list in copy construct that accepts an std::array
#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];
}
此代码在调试和发布模式下在 Visual Studio 2013 中符合要求,但在我编译时,智能感知会给出此错误:
智能感知:构造函数"CHL::Vector::Vector [type=double, ArraySize=4U]"的实例与 参数列表 参数类型为:({...}(
我的问题是C++中的有效代码吗?如果是,我如何阻止 IntelliSense 用此错误污染我的错误列表。
智能感知需要三对大括号:
class Vector {
Vector( //1 for initialization of vector
std::array<...> //1 for initialization and 1 for internal array
);
};
但是,该语言允许大括号省略,这意味着只需两个就可以了。我不确定为什么编译器会捕获这一点而 Intellisense 不会,但是如果您使用的是 CTP,它可能就像上次一样,编译器更改直到真正发布才反映在 Intellisense 中。
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 将初始化器列表/聚合初始化转发到 std::array 成员
- 为什么不能用两层列表初始值设定项初始化 2D std::array?
- 如何在类的初始值设定项列表中初始化 std::array,而不对数组的大小进行硬编码
- std::初始值设定项列表来自现有的 std::array,而不枚举每个元素
- 当 T 不可默认构造时,构造函数初始值设定项列表中 std::array<T,N> 的初始化
- 使用初始值设定项列表初始化结构,对于 std::array 失败
- 为什么大括号括起来的初始值设定项列表不适用于 std::array
- 在成员初始化列表中填充 std::array
- 有没有一种方法可以使用std::array与文字或初始值设定项列表进行比较,就像使用赋值一样
- 复制构造中接受 std::array 的初始器列表
- 用于初始化 2D std::array 成员的初始值设定项列表
- 如何在不直接提供大小的情况下创建带有初始化列表的 std::array
- std::vector和std::array初始值设定项列表之间的区别
- 将 rng 的列表存储在 std::array 中以进行多线程处理
- 如何为 std::array 的列表初始化构造函数编写包装器?
- c++11 constexpr将std::array的列表展开为数组
- 使用带有初始化列表的std::array
- 为什么std::array不包含初始化列表构造函数