[英]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 :: array大小,以使此示例正常工作。
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;
}
*这里有一些愚蠢的细节,不一定非要如此,而是等等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.