I tried to inherit from a template base class but I get several errors because my derived class is no template class. I also don't want it to be, I just want to share some variables and let the derived class implement them.
//base.h
template <typename T>
class Base
{
public:
explicit Base(QWidget *parent);
~Base();
protected:
QList<T*>* list;
T* selectedObject;
};
//base.cpp
#include "base.h"
template <typename T>
Base<T>::Base(QWidget* parent)
{
}
template <typename T>
Base<T>::~Base()
{
}
//derived.h
namespace Ui
{
class Derived;
}
class Derived: public QWidget, public Base<MyType>
{
Q_OBJECT
public:
explicit Derived(QWidget *parent = 0);
~Derived();
private:
Ui::Derived*ui;
};
//derived.cpp
Derived::Dervied(QWidget* parent) : QWidget(parent), Base<Mytype>(parent)
{
list = new QList<MyType*>();
}
So I e.g. want to implement this Qlist from the base class but with a specific type parameter like MyType. I haven't worked with templates in combination with inheritance before in c++ and I tried several things but they didn't work out.
EDIT So, I tried like dtbeaver explained below but then I get following error message: undefined reference to 'Base::Base()'. I get this for the constructor and deconstructor