Linking a template class using another template class (error LNK2001)
Posted
by Luís Guilherme
on Stack Overflow
See other posts from Stack Overflow
or by Luís Guilherme
Published on 2010-06-11T12:36:11Z
Indexed on
2010/06/11
12:52 UTC
Read the original article
Hit count: 249
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)
© Stack Overflow or respective owner