我有以下的模板類,錯誤在一個模板類的拷貝構造函數使用默認值
template <typename Real>
class Marker {
typedef Wm5::Vector3<Real> Position ;
typedef Wm5::Vector3<Real> Normal ;
typedef Wm5::Vector3<Real> Color ;
public:
Marker(int id = -1, Position position = Wm5::Vector3<Real>::ZERO, Normal normal = Wm5::Vector3<Real>::ZERO, Color color = Wm5::Vector3<Real>::ZERO)
: id_(id), position_(position), normal_(normal), color_(color), cluster_(-1) {}
~Marker() {}
private:
int id_ ;
Position position_ ;
Normal normal_ ;
Color color_ ;
int cluster_ ;
};
template <typename T>
class MarkerSet {
typedef Marker<T> MarkerT ;
typedef std::vector<MarkerT> MarkerVector ;
public:
MarkerSet::MarkerSet(int id = -1, MarkerVector markers = MarkerVector())
{id_ = id; markers_ = markers;}
MarkerSet::~MarkerSet() {}
private:
int id_ ;
MarkerVector markers_ ;
} ;
當我試圖通過
MarkerSet<double> markerSet ;
創建MarkerSet對象獲得這個連接錯誤,
error LNK2001: unresolved external symbol "public: __thiscall MarkerSet<double>::MarkerSet<double>(int,class std::vector<class Marker<double>,class std::allocator<class Marker<double> > >)" ([email protected]@@[email protected][email protected][email protected]@@[email protected][email protected]@@@[email protected]@@[email protected]@@Z)
我會非常感激,如果有人能給我一個指向正確的方向與regar指針ds到我做錯了什麼。
編輯:
好吧我已經縮小到一些奇怪的東西。
中.HMarkerSet(int id = -1, MarkerVector markers = MarkerVector())
{id_ = id; markers_ = markers;}
在的.cpp構建精細
而非.H
MarkerSet(int id = -1, MarkerVector markers = MarkerVector()) ;
template <typename T>
MarkerSet<T>::MarkerSet(int id, MarkerVector markers) {
id_ = id ;
markers_ = markers ;
}
錯誤列於上述的方式。
有什麼想法?
是否有可能你有一個陳舊的對象文件,使用舊的'MarkerSet'定義?試試你的IDE的「乾淨」或「重建所有」選項? – aschepler 2012-03-13 18:02:50
是的,我已經嘗試了一次清理並重建所有。 – oracle3001 2012-03-13 18:18:45