Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use .hpp files

I've created a library using C++, I want to create a Python Wrapper for this library and I am using boost.python - The problem is that I have created .h and .cpp files separately and for some reason, the .so file cannot link these .cpp files.

I have therefore decided to just use the .hpp extension and include the implementation as a header file. Is this good or bad practice in terms of C++? I'm hoping to upload my project to Github so want to maximize the most optimal solution.

P.S. I think this question would more belong on programmers.stackexchange.com so if it is, could someone please migrate it.

like image 718
Phorce Avatar asked Nov 16 '13 20:11

Phorce


People also ask

How do I run a .HPP file?

There are several applications that can be used to open HPP files such as Apple Xcode, Microsoft Visual Studio 2010, Code::Blocks, MacroMates TextMate, BloodshedSoftware Dev-C++, GNU project C and C++ compiler (GCC), etc.

Is HPP same as H file?

h is more widely used for header files than . hpp when, . h refers to C header and . hpp refers C++ header.

What does Ifndef mean in C++?

The #ifndef directive checks whether a macro is not defined. If the identifier specified is not defined as a macro, the lines of code immediately follow the condition are passed on to the compiler.

What are header files used for in C++?

Header files are used in C++ so that you don't have to write the code for every single thing. It helps to reduce the complexity and number of lines of code. It also gives you the benefit of reusing the functions that are declared in header files to different .


1 Answers

This is a good idea if you have mixed c++ and c in your project. As mentioned in the comments .hpp and .h are essentially the same (for compiling c++, not c). If you are having problems linking your project it's not because of your file extensions.

In the header files you typically 'prototype' the class definition so that all of your class members can be used, not just ones defined before the current code.

Please review: *.h or *.hpp for your class definitions

like image 112
James McDonnell Avatar answered Sep 21 '22 15:09

James McDonnell