我有以下簡單的模板代碼:模板 - 未定義的引用錯誤
#ifndef CLUSTER_H
#define CLUSTER_H
#include <iostream>
#include <vector>
template <typename T, size_t K>
class Cluster
{
public:
void Print() const;
private:
std::vector<T> objects;
};
template <typename T, size_t K>
void Cluster<T,K>::Print() const
{
for (int i=0; i<objects.size(); i++)
{
T curr=objects[i];
std::cout << curr << " ";
}
std::cout << std::endl;
}
#endif
出於某種原因,我得到以下錯誤:「未定義的引用‘Cluster<int, 5u>::Print() const
’可能是什麼造成這種情況的原因 ?謝謝!
你能提供一些代碼來產生錯誤,例如:致集羣 ::打印? –
Rook
http://ideone.com/cMTih適合我。 – Griwes
分享你的** main()**以及如何編譯你的程序。使用模板始終提供完整的錯誤消息。 – tuxuday