Search code examples
c++templatescoding-style

C++ Template implementation file extension convention?


Is there a convention for what file extension is used for template class implementation? **.tpp .template .hpp **


Solution

  • "Is there a convention for what file extension is used for template class implementation?"

    No there isn't really a standard convention established for these file extensions AFAIK.

    There's a number of file extensions commonly used though, like

    • .icc
    • .inl
    • .tcc (which seems at least to be used by my GCC 4.8.1 standard libraries implementation)
    • ...

    It doesn't really matter that much, because you'll need to be explicit about it with the #include "MyImpl.tcc", #include "MyImpl.tpp" statement in the template header file anyway.

    You could use for instance .tci (template class implementation, one I've invented creatively on the fly here ;-) )

    One important point is, you should use a consistent naming strategy over all of your projects involved to the solution (This would make it even easier to set up you IDE preferences for syntax highlighting).


    The only no go extensions IMHO are .cc, .cpp, .cxx and .c, which would confuse most of the automated build systems and IDE's currently around. The build system will assume these files need to be to build and linked as additional objects, and fail because of these either can't be build standalone, or ending up with multiple symbol definitions in linkage.