c++ - 未解析的外部符号

标签 c++ linker-errors unresolved-external

我收到一个链接错误,我不确定它指的是什么。

这里是错误

1>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall BinaryHeap,class std::allocator > >,class Comp,class std::allocator > > >::insert(class Item,class std::allocator > > const &)" (?insert@?$BinaryHeap@V?$Item@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@V?$Comp@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@@QAEXABV?$Item@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@Z) referenced in function "public: void __thiscall PriorityQueue,class std::allocator > >::insertItem(int,class std::basic_string,class std::allocator > const &)" (?insertItem@?$PriorityQueue@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEXHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

代码比较长,如果你想让我贴出来,我会贴出来的。

谢谢

最佳答案

它是一个模板函数,BinaryHeap<T, Comp>::insert(T const &) .您的 MSVC 编译器不支持可导出模板(很少支持)。确保您在头文件而不是 .cpp 文件中定义(不仅仅是声明)此函数。

关于c++ - 未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2660835/

相关文章:

c++ - CURL 不返回正确的错误代码

c++ - Qt ActiveX 动态调用返回值始终为空

c - 尝试在 Linux 上的 C/C++ 中使用 lp_solve 时出现 "undefined reference"

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?

c++ - 前摄器 VS react 器

c++ - C - 外部结构

c++ - Visual Studio 2012 - C MariaDB 客户端 - 错误 LNK2019 : unresolved external symbol _mysql_init@4

c++ - 为什么我突然从游戏项目中获得引用我的游戏引擎的未解析外部符号

c++ - BulletPhysics:错误 LNK2001:未解析的外部符号

C++ LNK2019 未解析的外部符号 stdlib