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

template class linker errorz

This topic is 5647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ahh help i'm senile i wanna program a nice template class. the problem is.. i'm senile. the functions of the class are programmed in a .cpp file with the same name of the .h like a normal programmer. BUT! whenever i try to execute the program i get lotsa silly linker errors like: "HEY YOU DIDN't PROGRAM THAT FUNCTION AT ALL!!!" "unresolved external symbol blah blah" but I DID!!! DARN!!!! and YES~! i include everyhting right! i'm sure of that. I even showed the code to my master programmer friend and he didn't tell me "gzoo you baboon do this not that" May The Gzoo Be With You! ~Lord Gzoo [edited by - lord gzoo on June 25, 2002 3:19:34 PM]

Share this post

Link to post
Share on other sites
Original post by Lord Gzoo
why? any reasonable explanation?

Because templates are instantiated on use. You can define any number of templated functions and classes, but until you use them, no code for them is generated. This is because you can''t instantiate a template without knowing the parameter types. Therefore, no code is generated from your .cpp files with template function definitions.

You can try explicit instantiation if your compiler supports it, something along the lines of

template <> vector<int>;

The exact syntax may be different, I forgot already. But your best bet is to define all template functions in headers.

Share this post

Link to post
Share on other sites