ERROR CODE:
CList<CString,const char*> test;
ERROR INFO:
ECLIPSE / UBUNTU 10
/home/latyas/workspace/CList/Debug/../test.cpp:7: undefined reference
to `CList<CString, char const*>::CList()'
I have already defined this constructor:
template<typename T1, typename T2> CList<T1, T2>::CList() :
m_nHead(0), m_nTail(0),m_nCount(0) {
}
Why am I getting this error?
updated:
#include <iostream>
#include "CString.h"
#include "CList.h"
int main()
{
CList<CString,const char*> test;
test.AddHead("test");
return 0;
}
/*
* CList.h
*
* Created on: 2012-3-31
* Author: latyas
*/
#ifndef CLIST_H_
#define CLIST_H_
template<typename T1,typename T2> class CList {
public:
struct CNode {
CNode* pNext;
CNode* pPrev;
T1 data;
};
CList();
~CList();
long GetHead();
long GetTail();
long GetNext(long, T1&);
long GetCount();
long AddHead(T2);
long AddTail(T2);
long RemoveAt(long);
private:
CNode* m_nHead;
CNode* m_nTail;
long m_nCount;
};
#endif /* CLIST_H_ */
/*
* CList.cpp
*
* Created on: 2012-3-31
* Author: latyas
*/
#include "CList.h"
#include <cstdlib>
#include <iostream>
/
template<typename T1, typename T2> CList<T1, T2>::CList() :
m_nHead(0), m_nTail(0),m_nCount(0) {
}
template<class T1, class T2> CList<T1, T2>::~CList() {
std::cout << "~CList()";
There is no .cpp file for templated classes, so all your implementation must be done in the .h file only..