Answer the question
In order to leave comments, you need to log in
When to use .h and .hpp?
Hello.
In one library, I came across files with the .hpp extension . After googling, I found out that this is a header extension for C ++, and for C, .h should be used .
But the vast majority of C++ books and manuals use .h .
Explain what is the difference between these extensions? Why do some projects use some extensions, while others use others? And why if .hpp is for C++ - people mostly use .h anyway? Is it bad form to use .hpp ?
Answer the question
In order to leave comments, you need to log in
Technically, the compiler does not care what extension you put in - you still specify the full name with the full extension when including. Therefore, put it as it is customary in your naming convention.
About c ++ and c - in principle you are right, but this is a recommendation, not a rule.
The .hpp extension is sometimes used when writing templates because implementing a template class function in a separate .cpp file will generate an error.
I usually use .hpp when the code is header-only and .h when there is also .cpp.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question