C++ Template implementation file extension convention?

醉酒当歌 提交于 2020-02-18 11:26:21

问题


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


回答1:


"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.




回答2:


No.

A lot of projects don't care much and just throw everything in the .hpp file. I do this.

A lot of other projects (big header-only ones like Eigen and Boost) split inlined code, and template implementations into .inl (for inline) files.

I've never personally seen .tpp, but that doesn't mean there aren't projects that do it.

But there's no convention, no.



来源:https://stackoverflow.com/questions/29264656/c-template-implementation-file-extension-convention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!