使用模板,出现连接错unresolved external symbol ,VC6编译环境下

mmmcd mmmcd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如下程序,写在一个cpp里,编译没有问题

//#pragma once
template<class T> class TestClass
{
public:

TestClass();
TestClass(int height, int width);
~TestClass();
};

//在.cpp中定义:
//#include "TestClass.h"
template<class T>
TestClass<T>::TestClass()
{
}
template<class T>
TestClass<T>::TestClass(int height, int width)
{
}
template<class T>
TestClass<T>::~TestClass()
{
}
*/
//在测试Cpp中:
//#include "TestClass.h"

int main()
{
TestClass<int> array2d(10, 10);
return 0;
}


如果TestClass的定义分开写到TestClass.h,和TestClass.cpp中,将有下面错误

test.obj : error LNK2019: unresolved external symbol "public: __thiscall TestClass<int>::~TestClass<int>(void)" (??1?$TestClass@H@@QAE@XZ) referenced in function _main
test.obj : error LNK2019: unresolved external symbol "public: __thiscall TestClass<int>::TestClass<int>(int,int)" (??0?$TestClass@H@@QAE@HH@Z) referenced in function _main

vc6的问题还是程序问题?
如何解决?
...全文

相关推荐

评论 19
收藏 已收藏
分享
返回顶部
mmmcd
C++ 语言 65,214 成员 250,514 内容