0

I'm getting an undefined reference error when attempting to inherit from a class that uses a template. Is there a way to pass the base class an instance of the templated parameter?

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()
{
}

I'm getting an error at the constructor of the 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()'
kitfox
  • 4,534
  • 3
  • 17
  • 24

0 Answers0