c++ – Difference between .h and .hpp


What is the difference between .h and .hpp in C ++ ? Which is better to use?


Strictly speaking, there is no difference between them at all. The only difference is how the IDE interprets them. .h , if you follow some logic, is the header for C ( .c ), while .hpp is the header for C ++ ( .cpp , .cxx etc.). But all this is conditional and depends on the preferences and IDEs used. For example, in Visual Studio we have .h and .cpp files by default.

In my opinion, the only place where different naming can be beneficial is in a project where C and C ++ code is combined. Then it's worth having .h / .c for C code and .hpp / .cpp for C ++ when. I don't see any other uses besides personal preferences.

Scroll to Top