Possible Duplicate:
Why can templates only be implemented in the header file?
Hello. I have a stupid program in c++ consisting in a header file with a class using template and a cpp file with implementations of methods.
This is the header:
namespace SynQueueing {
template < class T, unsigned long SIZE = 0 >
class CommQueue {
public:
CommQueue();
~CommQueue();
}
}
This is cpp
#include "myheader.h"
using namespace SynQueueing;
/* Default constructor */
template < class T, unsigned long SIZE >
CommQueue<T, SIZE>::CommQueue() {
}
/* Default destructor */
template < class T, unsigned long SIZE >
CommQueue<T, SIZE>::~CommQueue() {
}
In main I simply create an object of CommQueue
CommQueue cq;
Including CommQueue.h of course in cpp main file.
Well, compiler get crazy telling me this:
/tmp/ccvJL8VI.o: In function `main':
entry.cpp:(.text+0x2c): undefined reference to `SynQueueing::CommQueue::CommQueue()'
entry.cpp:(.text+0x10e): undefined reference to `SynQueueing::CommQueue::~CommQueue()'
entry.cpp:(.text+0x135): undefined reference to `SynQueueing::CommQueue::~CommQueue()'
collect2: ld returned 1 exit status
entry.cpp is the file where main is located. Any idea?
Thanks