用vs2005写c++项目,定义了AList类,在AList.h中写了类定义,有3个函数不是inline的,定义写在了AList.cpp中。但每次编译项目,那3个函数便报错
DataStruct.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall AList<int>::insert(int const &)" (?insert@?$AList@H@@UAE_NABH@Z)
DataStruct.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall AList<int>::append(int const &)" (?append@?$AList@H@@UAE_NABH@Z)
DataStruct.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall AList<int>::remove(int &)" (?remove@?$AList@H@@UAE_NAAH@Z)
解决这个错误可以:
1、使用了template,类定义和函数实现要在同一个文件。
2、可以include“AList.cpp”,但不知道对工程是否有负面影响。
本文介绍使用VS2005编译C++项目时遇到的模板类成员函数链接错误问题及解决方案。针对AList模板类的非内联成员函数在单独cpp文件中定义导致的未解析外部符号错误,提供了两种解决思路。
2万+

被折叠的 条评论
为什么被折叠?



