M
M
MrSayMyName2016-10-10 21:14:06
C++ / C#
MrSayMyName, 2016-10-10 21:14:06

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

4 answer(s)
G
GavriKos, 2016-10-10
@GavriKos

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.

N
Nexeon, 2016-10-10
@MrNexeon

The .hpp extension is sometimes used when writing templates because implementing a template class function in a separate .cpp file will generate an error.

D
Dmitry, 2016-10-12
@mezastel

I usually use .hpp when the code is header-only and .h when there is also .cpp.

A
abcd0x00, 2016-10-13
@abcd0x00

You can divide it like this: .h - if these files can be used in a C project; .hpp - if these files can only be used in a C++ project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question