未解析的外部符号

发布于 2024-08-28 22:54:08 字数 886 浏览 4 评论 0原文

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

这是错误

1>Main.obj:错误 LNK2019:无法解析的外部符号“public:void __thiscall BinaryHeap,类 std::allocator > >,class Comp,class std::allocator > > >::insert(类 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?$分配器@D@2@@std@@@@@@QAEXABV?$ Item@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@@Z) 在函数“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)

代码相当长,不过,如果你想让我发布它,我会的。

谢谢

I am getting a linking error, and I'm not sure what its referring to.

Here is the error

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)

The code is rather long, however if you want me to post it I will.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

﹉夏雨初晴づ 2024-09-04 22:54:08

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

It is a template function, BinaryHeap<T, Comp>::insert(T const &). Your MSVC compiler doesn't support exportable templates (very few do). Make sure you defined (not just declared) this function in a header file, not a .cpp file.

溇涏 2024-09-04 22:54:08

它表示您正在调用 BinaryHeap::insert 但没有链接该函数的实现。您必须有头文件,否则当您尝试调用未声明的函数时编译器会失败;您是否忘记链接 BinaryHeap 库?

It's saying you're calling BinaryHeap::insert but no implementation of that function is being linked in. You must have header files around or the compiler would've failed when you tried to call an undeclared function; did you forget to link a BinaryHeap library?

娇纵 2024-09-04 22:54:08

您是否正在尝试定义模板化的 BinaryHeap 类?您是否在 .h 文件中声明插入方法并在 .cc 文件中定义它?

这在大多数编译器上不起作用。您需要定义模板函数,以便它们在编译时可用,而不仅仅是链接时可用。将函数定义移动到头文件中。

Are you trying to define a templated BinaryHeap class? Are you declaring the insert method in the .h file and defining it in the .cc file?

That doesn't work on most compilers. You need to define template functions so they are available at compile time, not just link time. Move the function definition to the header file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文