Home Why can templates only be implemented in the header file?
Reply: 0

Why can templates only be implemented in the header file?

user8198
1#
user8198 Published in September 19, 2018, 9:53 am

Quote from The C++ standard library: a tutorial and handbook:

The only portable way of using templates at the moment is to implement them in header files by using inline functions.

Why is this?

(Clarification: header files are not the only portable solution. But they are the most convenient portable solution.)

share|improve this question
  • 41
    The question is incorrect. There is another portable way. The template class can be explicitly instantiated - as has been pointed out by other answers. – Aaron McDaid Aug 27 '12 at 11:42
  • 10
    While it is true that placing all template function definitions into the header file is probably the most convenient way to use them, it is still not clear what's "inline" doing in that quote. There's no need to use inline functions for that. "Inline" has absolutely nothing to do with this. – AnT Sep 18 '14 at 4:11
  • 6
    Book is out of date. – gerardw Oct 11 '14 at 13:25

14 Answers 14

active oldest votes
up vote 1230 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.481524 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO