1

Possible Duplicate:
Why can templates only be implemented in the header file?

I have written template method in non-template class. This project is static library. Then I have written test console application and wanted to use this method. But there is compilation error (unresolved external). Then I asked google and have found forum (http://cboard.cprogramming.com/cplusplus-programming/108544-static-libraries-template-functions.html) where 'matsp' said: "The entire template implementation needs to be in a header file when using templates.". I did like he said and it works great. Why?

Community
  • 1
  • 1
Lex
  • 161
  • 1
  • 13

1 Answers1

0

Because that's the way it is with templates in C++... Their definition has to be visible in every translation unit that is used.

K-ballo
  • 80,396
  • 20
  • 159
  • 169