在 C++11 中使用模板在类内创建不同长度的数组
Using a template to create arrays of varying length inside of class in C++11
假设我有一个类:
template <int S1>
class Cont {
private:
std::array<int, S1> nums;
public:
Cont(std::array<int, S1> ns);
}
尝试链接我的程序时,我收到一个错误,例如,Cont(std::array ns)未定义。那么我做错了什么吗?还是由于数组的工作方式,这永远不会起作用?
编辑:抱歉,我应该提到构造函数已定义。我给出标题只是为了说明我的意思。
Cont(std::array<int, S1> ns)
只是一个声明,你也需要定义它。
喜欢:
Cont(std::array<int, S1> ns){
// code
}
相关文章:
- 在c++中为double类型的数组创建一个unique_ptr
- 如何从预定义的数组创建某些元素数组
- 基于数组的列表 - 动态数组创建时出错
- 从 UTF-8 字节数组创建字符串?
- 是否可以在并行区域中为共享 2D 数组创建选定元素的线程本地副本?(共享,私有,障碍:OPenMP)
- C++ 从名称数组创建对象
- 从数组创建 Mat 时,'cv::Mat' 和 'int' 类型不兼容
- 从 std::数组创建十六进制代表
- 在 C++ 结构内声明的数组 A[1] 创建多个实例
- 为多维数组创建内存空间
- 如何使用任何类型的数组创建模板类并为其设置值?
- 从字符串数组创建一个字符数组
- 是否可以在不为该数组创建变量的情况下将数组作为参数传递到函数中?
- 使用类定义数组创建C++类
- 使用具有唯一随机数的结构数组创建多个对象
- 谷歌测试:无法从字符数组创建字符串
- 从 1D 数组创建 2D 数组
- 无法通过一个单向链表数组创建邻接列表
- 如何使用数组创建标准::函数
- 在C++中,返回从本地字符数组创建的字符串是否会导致内存泄漏或未定义的行为