#### Archived

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

# c++ strange linking with templates

## Recommended Posts

friman    122
hi this is about c++ strange linking and compilation phenomenon. I created a general algorythm function in c++: ******** a.cpp ************

template <class T>
{ ......
general.print(); }

************************* As you can see, the function takes an object of type T and calls the print() function of that object. One weird thing is that even if I change the line general.print(); to be stupid.print(); although there is no 'stupid' object defined, still the compilation of the function succeeds. the function is called from main: ******** main.cpp ***********

#indlude "data.h"
data mdata;
template <class T>
.....

************** ok, so the compilation works fine, but not the linking: error LNK2001: unresolved external symbol.... is created I would really apprise it, could you explain me how overcome this weirdness ? [edited by - friman on April 29, 2003 5:28:54 AM]

##### Share on other sites
dalleboy    324
template functions should be put in header-files (.h)

Update GameDev.net system time campaign - success at last

##### Share on other sites
friman    122
dalleboy you solved my problem,
thank-you
and again thak you, I could spend more void hours
I didn''t know that