template conversion problems

Started by
5 comments, last by bobster 20 years, 8 months ago
Hi, I''ve been writing a simple platformer within which I have made my own linkedlist class and an associated iterator. However, and stupidly, I thought that to start with I could make the list just take a particular object pointer, and not build it as a template from teh beginning. Today I decided to change this so the two classes acted as templates I have now amended the linkedlist class, the iterator, and all the references to them in the other implementation files so all the ''s and ''s have been put in the right places to make the two classes templates. I started out with 110 compile errors to sort after my first attempt, but they quickly got knocked out as i put in the missing template arguments I had missed, until i thought I had got the last one. However, just as I had eliminated the last missing , instead of the program compiling correctly I got the error message: main.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkedList::LinkedList(class LinkedList const &)" (??0?$LinkedList@PAVRabbit@@@@QAE@ABV0@@Z) main.obj : error LNK2001: unresolved external symbol "public: class LinkedList & __thiscall LinkedList::operator=(class LinkedList const &)" (??4?$LinkedList@PAVRabbit@@@@QAEAAV0@ABV0@@Z) world.obj : error LNK2001: unresolved external symbol "public: class LinkedList & __thiscall LinkedList::operator=(class LinkedList const &)" (??4?$LinkedList@PAVRabbit@@@@QAEAAV0@ABV0@@Z) main.obj : error LNK2001: unresolved external symbol "public: void __thiscall LinkedList::Append(class Rabbit * &)" (?Append@?$LinkedList@PAVRabbit@@@@QAEXAAPAVRabbit@@@Z) .\Debug/billboard.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. A load of unresolved externals. Considering I don''t even properly understand what an unresolved external is, I''m in a bit of trouble, but I''m expecting it to have a simple solution, as my code worked fine before and it should be a fairly easy job to convert one of the classes (which was working perfectly) to a template. Any advice?
Advertisement
An unresolved external is a function that has been declared, but never defined. That is, it appears in the class definition, but there''s no body for it anywhere.

How appropriate. You fight like a cow.
so are you saying that this is probably being caused by a member function being called which is in the linkedlist header file, but its corresponding implementation in linkedlist.cpp is not labelled correctly so its not finding that member function''s implementation?
I took what you said onboard and after checking that prototypes of the member functions were all labelled correctly, I still couldn''t find a problem. Then I took a brute force approach and cut the whole implementation file and pasted it all into the bottom of the header file for the linkedlist class i created. This solved the problem, but obviously I would prefer it if I could get the implementation back into the cpp file. I really don''t understand why it should work one way and not the other, as the header file is include''d in the cpp file. What can I do to the cpp file to be able to have all the implementation back there and not get these ''unresolved external'' errors?
Are you using the ''inline'' keyword somewhere around these functions? I''ve had the similar problem that the compiler couldn''t find inlined functions that aren''t defined inside the header file.
How do I set my laser printer on stun?
no unfortunately none of the 3 offending functions are used inline at all
Ahhhh... I missed that the errors had template arguments. In the future, put stuff like that in [ source ] and [ /source ] tags; web browsers have a habit of gobbling up templates in source code.

The deal here is that, currently, templated functions and functions of templated classes MUST be defined in the class definition. Sorry, but that''s the way the cookie crumbles.

How appropriate. You fight like a cow.

This topic is closed to new replies.

Advertisement