【发布时间】:2010-06-11 12:36:11
【问题描述】:
我使用一个抽象模板类和两个子类实现了“策略”设计模式。是这样的:
template <class T>
class Neighbourhood {
public:
virtual void alter(std::vector<T>& array, int i1, int i2) = 0;
};
和
template <class T>
class Swap : public Neighbourhood<T> {
public:
virtual void alter(std::vector<T>& array, int i1, int i2);
};
还有一个子类,和这个一样,alter是在cpp文件中实现的。好的!现在我在另一个类中声明另一个方法(当然包括neighbourhood 头文件),像这样:
void lSearch(/*parameters*/, Neighbourhood<LotSolutionInformation> nhood);
它编译得很好而且很干净。开始链接时,出现以下错误:
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)
【问题讨论】:
标签: c++ visual-studio visual-c++ templates abstract-class