Possible Duplicate:
Why can templates only be implemented in the header file?
Undefined reference to template members
c++ template and header files
I am getting a compiler error when using a function template in a class. The function template was declared in a namespace in a separate source and header file.
Here is some example code.
namespace A header file
namespace A {
...
...
template<typename T1, typename T2 >
bool OR(T1* j, vector<T2*>, float cut);
...
...
}
A cpp file
namespace A {
...
...
template<typename T1, typename T2 >
bool OR(T1* j, vector<T2*>, float cut){
....
....
}
}
I then use this namespace in a class
class B cpp file ( only member function)
#include "A.h"
void B::exmaple(){
if(A::OR(m_ptrObj, m_ptrvectortoOtherObj, m_cut)){
cout << "its true" << endl;
}
}
So the compiler error I get is as follows (Note this is the error from my real code, but same idea).
undefined reference to `bool JetFilters::OR<Jet, Jet>(Jet*, std::vector<Jet*, std::allocator<Jet*> >*, float)
Any ideas why I am getting the above error??