why template are defined in .h [duplicate]
Possible Duplicates:
Why should the implementation and the declaration of a template class be in the same header file? Why can templates only be implemented in the header file?
I'm not really understand why it's olbiged to define template implementation in a .h file?
Could someone give me a detail answ开发者_如何转开发er ?
Thanks!
Because the compiler needs the code to instantiate the template. If you put a template implementation into a .cpp file, you will be only able to instantiate the template in that .cpp file.
精彩评论