I'd like to create my own template class for Thread. As template arguments I'd like to set: function to be called when thread starts, class of parameter passed to the previously defined function, function to be called after thread ends and class of parameter returned by previous function.
So I want something like this:
In header file:
template<typename taskClass, typename taskDataClass, typename endCallbackClass, typename endCallbackDataClass>
class Thread {
public:
Thread();
private:
bool mIsActive;
bool mIsDone;
pthread_t mPThread;
taskClass mTask;
taskDataClass mTaskData;
endCallbackClass mEndCallback;
endCallbackDataClass mEndCallbackData;
}
In cpp file:
#include "Thread.h"
template<typename taskClass, typename taskDataClass, typename endCallbackClass, typename endCallbackDataClass>
Thread<taskClass, taskDataClass, endCallbackClass, endCallbackDataClass>::Thread() {
}
However creating an instance of such class causes troubles:
auto th = new Thread<std::function<void(bool)>, bool, std::function<void(int)>, int>();
Error is:
undefined reference to `Thread<std::function<void (bool)>, bool, std::function<void (int)>, int>::Thread()'
Can anybody explain to me what is the problem in this case? I don't see the problem...