可能重複:
Why do I get 「unresolved external symbol」 errors when using templates?無法解析的外部與模板
我試圖實現使用模板的通用隊列。
我有下面的代碼在我的頭:
template<class Item>
class Queue{
protected:
struct linked_list;
int size;
public:
Queue();
Queue(Item T);
};
我有一個Queue.cpp:
template<class Item>
Queue<Item>::Queue()
{
}
template<class Item>
Queue<Item>::Queue(Item T)
{
}
但我每次編譯的時候,我得到的,因爲無法解析外部的連接錯誤。
我重新安裝了VS2012兩次(認爲鏈接器壞了),但問題不斷出現。
我讀過使用模板時,函數實現在單獨的文件中存在一些問題,但是我沒有看到任何解決方案,除了將實現放在標題中。
有沒有更優雅的方式來做到這一點?
查看http://stackoverflow.com/questions/3749099 – aschepler