Linking a template class using another template class (error LNK2001)
- by Luís Guilherme
I implemented the "Strategy" design pattern using an Abstract template class, and two subclasses. Goes like this:
template <class T>
class Neighbourhood {
public:
virtual void alter(std::vector<T>& array, int i1, int i2) = 0;
};
and
template <class T>
class Swap : public Neighbourhood<T> {
public:
virtual void alter(std::vector<T>& array, int i1, int i2);
};
There's another subclass, just like this one, and alter is implemented in the cpp file. Ok, fine! Now I declare another method, in another class (including neighbourhood header file, of course), like this:
void lSearch(/*parameters*/, Neighbourhood<LotSolutionInformation> nhood);
It compiles fine and cleanly. When starting to link, I get the following error:
1>SolverFV.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall lsc::Neighbourhood<class LotSolutionInformation>::alter(class std::vector<class LotSolutionInformation,class std::allocator<class LotSolutionInformation> > &,int,int)" (?alter@?$Neighbourhood@VLotSolutionInformation@@@lsc@@UAEXAAV?$vector@VLotSolutionInformation@@V?$allocator@VLotSolutionInformation@@@std@@@std@@HH@Z)