#### Archived

This topic is now archived and is closed to further replies.

# template conversion problems

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
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?

##### Share on other sites
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.

##### Share on other sites
no unfortunately none of the 3 offending functions are used inline at all

##### Share on other sites
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.

• ### Forum Statistics

• Total Topics
628383
• Total Posts
2982382

• 10
• 9
• 15
• 24
• 11