【发布时间】:2019-12-12 15:59:30
【问题描述】:
我正在 c++ 中创建一个特征,它将我制作的另一个特征作为模板输入。 但是,当我运行此代码时,会出现以下编译器错误:
错误:模板参数的数量错误(1,应该是 2)模板 a>
代码如下:
enum class Unit { km, m, cm };
template<int v, Unit u>
struct Measure
{
public:
static const int value = v;
static const Unit unit = u;
};
template< Measure<int v, Unit u> a>
struct Measure_add
{
public:
static const int value = a::value;
static const Unit unit = a::unit;
};
用法应该是:
std::cout << Measure_add< Measure<4, Unit::m> >::value << std::endl;
这应该给出:
4
【问题讨论】:
标签: c++ templates struct traits