使std:数组大小取决于类模板参数
Make std:array size depending on class template parameter
让我们考虑以下非常简单的例子
#include <array>
template<typename T, F>
class GenericColor {
protected:
std::array<T, F> components;
}
class RGB : public GenericColor<int, 3> { // three components, red, green...
}
class CMYK : public GenericColor<int, 4> { // four components, cyan, magenta....
}
我的问题是如何使第二个参数指向std::数组大小,只是为了使这个例子工作
std::array
的声明为*
template<class T, std::size_t N> struct array
告诉你如何写代码:
template<typename T, std::size_t F>
class GenericColor {
protected:
std::array<T, F> components;
}
*这里有一些空洞的细节,不需要完全是这样的,但是blah blah blah不相关
相关文章:
- 将强制转换简化为取决于参数的类型
- cpp 模板专用化,错误说参数 1 的类型为 T,这取决于参数 T
- 模板函数,其中模板参数类型取决于函数参数
- GCC:指定的界限取决于源参数的长度
- 具有尾随返回类型的通用 lambda,具体取决于 C++11 中的可变参数
- 类模板中的std ::数组的大小,具体取决于模板参数
- LIBELAS是否取决于相机参数
- 具有取决于模板参数的方法的模板类
- 模板层次结构中的可选虚拟函数,具体取决于参数
- 约束模板参数取决于传递的函子
- 为什么固定尺寸错误发生取决于默认参数
- C++14 lambda 的默认参数类型推导,具体取决于前面的参数
- 委托构造函数和默认参数,具体取决于其他参数
- 取决于参数的数量,将其返回结构对象,并将其分配给常规结构的对象
- 具有模板参数取决于参数列表
- 返回类型取决于模板参数
- 是否可以定义一个 C++11 可变参数类模板,其可变参数基数取决于整数模板参数
- 返回取决于sizeof的变量类型..参数包
- 模板化结构的友元函数,其参数类型取决于结构的内部
- 变量模板函数,其中返回类型取决于模板参数列表