尝试从使用模板的类继承时,出现undefined reference
错误。有没有一种方法可以向基类传递模板化参数的实例?
template <typename T>
class Property
{
T _value;
public:
Property(const T& initValue);
~Property();
virtual QString propertyId() = 0;
virtual T value() { return _value; }
virtual void setValue(const T& value) { _value = value; }
};
template<typename T>
Property<T>::Property(const T& initValue)
:_value(initValue)
{
}
template<typename T>
Property<T>::~Property()
{
}
class PropertyReal : public Property<qreal>
{
static const QString ID;
public:
PropertyReal();
virtual ~PropertyReal();
QString propertyId() override { return ID; }
};
const QString PropertyReal::ID = "real";
PropertyReal::PropertyReal()
:Property(0.0)
{
}
PropertyReal::~PropertyReal()
{
}
我在PropertyReal :: PropertyReal()的构造函数中遇到错误:
D:\longpath\PropertyReal.cpp:10: error: undefined reference to 'Property<double>::Property(double const&)'
D:\longpath\PropertyReal.cpp:14: error: undefined reference to 'Property<double>::~Property()'