C++ templates declare in .h, define in .hpp

后端 未结 7 1735
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 05:08

I saw some code in which the developer defined a class template in a .h file, and defined its methods in a .hpp file. This caught me a bit by surprise.

Are there are

7条回答
  •  囚心锁ツ
    2020-12-05 05:49

    I've never heard of putting class declarations in .h and template definitions in .hpp. Every project I've seen has taken the approach that .h and .hpp mean the same thing and you should standardize on one (usually .h).

    Template methods can be put at the end of the .h file, or they can be put in separate -inl.h files (as suggested by the Google C++ Style Guide, for example).

提交回复
热议问题