可能重复:
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