我正在尝试编写一个小型单元库,以熟悉泛型编程和隐式转换。我选择在各自的维度下将单位组织成结构。为了在单元之间隐式转换,为兼容单元创建了构造函数。在应用允许任何数字类型占用lengthValue的模板之前,代码段很高兴。我现在得到以下错误,但我不知道如何解决它。
#include <type_traits>
class Distance
{
template<typename GenericNumber, typename = typenamestd::enable_if<std::is_arithmetic<GenericNumber>::value, GenericNumber>::type> struct feet;
template<typename GenericNumber, typename = typename std::enable_if<std::is_arithmetic<GenericNumber>::value, GenericNumber>::type> struct inches;
template<typename GenericNumber, typename = typename std::enable_if<std::is_arithmetic<GenericNumber>::value, GenericNumber>::type>
struct feet
{
public:
feet(GenericNumber _distance);
feet(feet& _distance);
feet(inches _distance);
inline GenericNumber getLength() { return lengthValue; }
private:
GenericNumber lengthValue = 0.0;
};
template<typename GenericNumber, typename = typename std::enable_if<std::is_arithmetic<GenericNumber>::value, GenericNumber>::type>
struct inches
{
public:
inches(GenericNumber _distance);
inches(feet _distance);
inches(inches& _distance);
inline GenericNumber getLength() { return lengthValue; }
private:
GenericNumber lengthValue = 0.0;
};
};
错误:
Error C2955 use of class template requires template argument list
代表行
feet(inches _distance);
inches(feet _distance);
答案 0 :(得分:0)
feet(inches<GenericNumber> _distance);
inches(feet<GenericNumber> _distance);
我需要指定我所指的模板类型作为参数,现在看来很明显