[英]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.