I have been reading up on creating template classes and I think I have it.. well, apart from one annoying bug I can't figure!
this is what I have so far:
template<class T>
class CStateMachine
{
public:
// Constructor
CStateMachine(QByteArray smName);
private:
QByteArray _smName;
};
// Here is the constructor implementation
template <class T>
CStateMachine<T>::CStateMachine(QByteArray smName):
_smName(smName)
{
qDebug() << "New statemachine:" << _smName << endl;
}
// Now here is the usage called from normal class CRpeComms:
#include "cstatemachine.h"
...
CStateMachine<CRpeComms> rpeSm("test");
...
This generates an error:
unidentified reference to CStateMachine<CRpeComms>::CStateMachine(QByteArray)
Note: I am using Qt so if you are not familiar with that then think of qDebug() and std::out or similar and QByteArray as CString or similar.
I have looked at lots of example and mine seems identical. If I move the implementation of my constructor into the header file (like below) then it works no problem...:
CStateMachine(QByteArray smName):
_smName(smName)
{
qDebug() << "new statemachine:" << _smName << endl;
}
So I am not sure what I am doing wrong here...
Any help much appreciated!