I'm answering this as an reminder, to give point to my comment(s) on "user1949346" answer to this same OP.
So as many already answered: either way is fine.
Followed by emphasizes of their own impressions.
Introductory, as also in the previous named comments stated, my opinion is C++
header extensions are proposed to be .h
if there is actually no reason against it.
Since the ISO/IEC documents use this notation of header files and no string matching to .hpp
even occurs in their language documentations about C++
.
But I'm now aiming for an approvable reason WHY either way is ok, and especially why it's not subject of the language it self.
So here we go.
The C++
documentation (I'm actually taking reference from the version N3690) defines that a header has to conform to the following syntax:
2.9 Header names
header-name:
< h-char-sequence >
" q-char-sequence "
h-char-sequence:
h-char
h-char-sequence h-char
h-char:
any member of the source character set except new-line and >
q-char-sequence:
q-char
q-char-sequence q-char
q-char:
any member of the source character set except new-line and "
So as we can extract from this part, the header file name may be anything that is valid in the source code, too. Except containing '\n'
characters and depending on if it is to be included by <>
it is not allowed to contain a >
.
Or the other way if it is included by ""
-include it is not allowed to contain a "
.
In other words: if you had a environment supporting filenames like prettyStupidIdea.>
, an include like:
#include "prettyStupidIdea.>"
would be valid, but:
#include <prettyStupidIdea.>>
would be invalid. The other way around the same.
And even
#include <<.<>
would be a valid includable header file name.
Even this would conform to C++
, it would be a pretty pretty stupid idea, tho.
And that's why .hpp
is valid, too.
But it's not an outcome of the committees designing decisions for the language!
So discussing about to use .hpp
is same as doing it about .cc
, .mm
or what ever else I read in other posts on this topic.
I have to admit I have no clue where .hpp
came from1, but I would bet an inventor of some parsing tool, IDE or something else concerned with C++
came to this idea to optimize some internal processes or just to invent some (probably even for them necessarily) new naming conventions.
But it is not part of the language.
And whenever one decides to use it this way. May it be because he likes it most or because some applications of the workflow require it, it never2 is a requirement of the language. So whoever says "the pp is because it is used with C++", simply is wrong in regards of the languages definition.
C++ allows anything respecting the previous paragraph.
And if there is anything the committee proposed to use, then it is using .h
since this is the extension sued in all examples of the ISO document.
Conclusion:
As long you don't see/feel any need of using .h
over .hpp
or vise versa, you shouldn't bother. Because both would be form a valid header name of same quality in respect to the standard. And therefore anything that REQUIRES you to use .h
or .hpp
is an additional restriction of the standard which could even be contradicting with other additional restrictions not conform with each other. But as OP doesn't mention any additional language restriction, this is the only correct and approvable answer to the question
"*.h or *.hpp for your class definitions" is:
Both are equally correct and applicable as long as no external restrictions are present.
1From what I know, apparently, it is the boost framework that came up with that .hpp
extension.
2Of course I can't say what some future versions will bring with it!