c++ 11和Visual Studio -无法解析的外部符号
C++11 and Visual Studio - unresolved external symbol
我尝试在Visual Studio 2013中运行我的c++代码。该代码在gcc 4.9
之前运行。我不知道为什么代码在Visual Studio中不运行。我把代码上传到GitHub上,这样每个人都可以看看它。请帮帮我。我真的不知道为什么代码不能在Visual Studio中运行。
Error 1 error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,1>::Property<int,1>(class std::function<int __cdecl(void)> const &,class std::function<void __cdecl(int)> const &)" (??0?$Property@H$00@Property@********@@QAE@ABV?$function@$$A6AHXZ@std@@ABV?$function@$$A6AXH@Z@4@@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 2 error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,1>::operator int const (void)" (??B?$Property@H$00@Property@********@@QAE?BHXZ) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 3 error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator=(int const &)" (??4?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 4 error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator+=(int const &)" (??Y?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 5 error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator-=(int const &)" (??Z?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 6 error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator*=(int const &)" (??X?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 7 error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator/=(int const &)" (??_0?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 8 error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator%=(int const &)" (??_1?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 9 error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,2>::Property<int,2>(class std::function<int __cdecl(void)> const &)" (??0?$Property@H$01@Property@********@@QAE@ABV?$function@$$A6AHXZ@std@@@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 10 error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,2>::operator int const (void)" (??B?$Property@H$01@Property@********@@QAE?BHXZ) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 11 error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,3>::Property<int,3>(class std::function<void __cdecl(int)> const &)" (??0?$Property@H$02@Property@********@@QAE@ABV?$function@$$A6AXH@Z@std@@@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 12 error LNK2019: unresolved external symbol "public: void __thiscall ********::Property::Property<int,3>::operator=(int)" (??4?$Property@H$02@Property@********@@QAEXH@Z) referenced in function _main C:Users#######documentsvisual studio 2013Projects********PropertyPropertyTest.obj Property
Error 13 error LNK1120: 12 unresolved externals C:Users#######documentsvisual studio 2013Projects********DebugProperty.exe Property
[关闭]
就像Praetorian写的那样,模板类不能轻易地分成头文件(.h)和源文件(.cpp)。原因是"编译器用给定的模板参数创建一个新类。"quote
将模板类拆分为头文件(.h)和源文件(.cpp)的解决方案如下:
// HEADER File test.h
#ifndef __TEST_FH__
#define __TEST_FH__
template<typename T>
class test {
public:
T object;
test();
~test();
};
#include "test.cpp"
#endif
// SOURCE File test.cpp
#ifdef __TEST_FH__
#ifndef __TEST_SOURCE_FH__
#define __TEST_SOURCE_FH__
template<typename T>
test::test() {
//code
}
template<typename T>
test::~test() {
//code
}
#endif
#endif
再次感谢你,禁卫军。
相关文章:
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector