Link error [modified]
-
when i changed the main function of a template class into a separate file, i have got a link error.Display is a function in the template class error LNK2001: unresolved external symbol "public: void __thiscall Gen_Queue<int>::Display(void)" (?Display@?$Gen_Queue@H@@QAEXXZ) What may be the problem? Anyone know the solution? I was coding a generic queue. i have made GenericQueue.cpp with functions Add(), delete() and display(). genericQueue.h have the variables and declaration of the functions. In another file GenericQueueMain.cpp i have written the function main() for the generic queue. I have made an object for the GenericQueue and tried to call the functions . Then i got the error-- error LNK2001: unresolved external symbol "public: void __thiscall Gen_Queue<int>::Display(void)" (?Display@?$Gen_Queue@H@@QAEXXZ)
modified on Tuesday, October 13, 2009 6:23 AM
-
when i changed the main function of a template class into a separate file, i have got a link error.Display is a function in the template class error LNK2001: unresolved external symbol "public: void __thiscall Gen_Queue<int>::Display(void)" (?Display@?$Gen_Queue@H@@QAEXXZ) What may be the problem? Anyone know the solution? I was coding a generic queue. i have made GenericQueue.cpp with functions Add(), delete() and display(). genericQueue.h have the variables and declaration of the functions. In another file GenericQueueMain.cpp i have written the function main() for the generic queue. I have made an object for the GenericQueue and tried to call the functions . Then i got the error-- error LNK2001: unresolved external symbol "public: void __thiscall Gen_Queue<int>::Display(void)" (?Display@?$Gen_Queue@H@@QAEXXZ)
modified on Tuesday, October 13, 2009 6:23 AM
What files? What is the 'main function' of a template file? What were the changes (i.e. There are chances you'll post the relevant code?)? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
when i changed the main function of a template class into a separate file, i have got a link error.Display is a function in the template class error LNK2001: unresolved external symbol "public: void __thiscall Gen_Queue<int>::Display(void)" (?Display@?$Gen_Queue@H@@QAEXXZ) What may be the problem? Anyone know the solution? I was coding a generic queue. i have made GenericQueue.cpp with functions Add(), delete() and display(). genericQueue.h have the variables and declaration of the functions. In another file GenericQueueMain.cpp i have written the function main() for the generic queue. I have made an object for the GenericQueue and tried to call the functions . Then i got the error-- error LNK2001: unresolved external symbol "public: void __thiscall Gen_Queue<int>::Display(void)" (?Display@?$Gen_Queue@H@@QAEXXZ)
modified on Tuesday, October 13, 2009 6:23 AM
Your question is not really clear but I guess you are trying to move the definition of a template class from a header file to a cpp file. Am I right ? If that is the case, you can't do something like that. For a template class, the full definition of the class and functions has to be known when compiling, thus you have to include everything in the header file. One 'trick' to get around that problem is to move the definition in a .inl file (to differentiate from a standard cpp file) and include that file in your header file (at the bottom of the file).
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++