我使用抽象模板類和兩個子類實現了「策略」設計模式。是這樣的:使用其他模板類鏈接模板類(錯誤LNK2001)
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)" ([email protected][email protected]@@@[email protected]@[email protected]@@[email protected]@@@[email protected]@@[email protected]@[email protected])
實際上,您可能更喜歡使用對鄰居而不是指針的引用。 – 2010-06-11 14:33:14
我會upvote,如果它不是說你必須使用指針。 @Luc說什麼 – 2010-06-12 10:32:56
謝謝你們倆:) – 2010-06-30 13:18:11