1

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

0

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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?

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.