使用模板,出现连接错unresolved external symbol ,VC6编译环境下
如下程序,写在一个cpp里,编译没有问题
如果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的问题还是程序问题?
如何解决?
//#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的问题还是程序问题?
如何解决?
...全文
相关推荐
关于VC6.0中 运行错误 unresolved external symbol _WinMain@16的解决
解决 VC6.0 中运行错误 unresolved external symbol _WinMain@16在使用 VC6.0 进行编程时,可能会遇到一个常见的错误:unresolved external
vc报error LNK2001unresolved external symbol的解决方法
"解决VC报错Error LNK2001:unresolved external symbol的方法"在编程过程中,尤其是在使用Visual C++(VC)进行开发时,开发者可能会遇到一个常见的链
解决error LNK2001: unresolved external symbol
一、解决error LNK2001: unresolved external symbol在VC网络编程中在VC网络编程中,可能会遇到error LNK2001: unresolved external
报error LNK2001 unresolved external symbol错就是因为你...
visual c++报error LNK2001 unresolved external symbol错就是因为你...
提示出现unresolved external symbol _main的解决方法
当开发过程中遇到"unresolved external symbol _main"或类似错误时,这通常是由于项目配置问题导致的链接错误。在不使用MFC AppWizard创建MFC项目时,如果项目参


