3

Should I be just using '.cpp' or '.template'?

Places I've checked don't seem to care for file extensions so I'm not sure what the expectation is.

Matthew Muller
  • 199
  • 2
  • 12
  • I've seen `.tpp`, but don't know what would be preferred. – A.E. Drew Oct 10 '13 at 23:31
  • 4
    templates are generally in header files – alrikai Oct 10 '13 at 23:47
  • 1
    From GCC's man page; C++ source files conventionally use one of the suffixes .C, .cc, .cpp, .CPP, .c++, .cp, or .cxx; C++ header files often use .hh, .hpp, .H, or (for shared template code) .tcc; so in header files, og .tcc files (github reconizes .tcc as c++ code). – Skeen Oct 10 '13 at 23:48
  • 6
    My rule is, if it goes into a `#include` it gets a .h extension. – Mark Ransom Oct 11 '13 at 00:03
  • Follow the existing naming conventions of the project. If it's a new project, I recommend putting templates in .h files, but some people prefer to split them over .h and .cpp files. I've never seen .template before. That said, it's all preference, so this question has no correct answer. – Dennis Oct 11 '13 at 00:11
  • 1
    There is no '*correct* extension': it's all a matter of convention and what your compiler accepts; but I agree with all the posters who have said you should use .h or .hpp. – user207421 Oct 11 '13 at 00:31
  • Either in regular header file, or one convention is you can separate definitions from implementation by using `.inl` (_inline_) for implementation of inline/template functions. – atablash Nov 29 '19 at 15:46

1 Answers1

3

C++ template program requires everything in the header file, usually, therefore it would be either .h or really any extension your IDE supports, and most major IDEs don't care about the extension of a header file as long as you properly spell it when you include it.

johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • 2
    Generally speaking, yes, but C++11 also supports "extern templates," which can have their implementations outside of the current translation unit (i.e. outside of a header file). – Jim Garrison Oct 11 '13 at 01:05