19

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.

Phorce
  • 2,632
  • 13
  • 43
  • 76
  • 22
    `.hpp` and `.h` are the same thing. – chris Nov 16 '13 at 20:40
  • 2
    @chris Hey, I thought the .hpp invoked that the implementation of the class would be in there? The general question is: Is this acceptable? I've always been taught to have a .h and .cpp file – Phorce Nov 16 '13 at 20:44
  • http://stackoverflow.com/questions/152555/h-or-hpp-for-your-class-definitions – JBentley Nov 16 '13 at 20:48
  • 2
    If you are going to put implementation in the header file, make sure to use `inline` where appropriate to avoid link errors (and be aware of which types of functions are automatically `inline` in a header file) – JBentley Nov 16 '13 at 20:49
  • 1
    Possible duplicate of [\*.h or \*.hpp for your class definitions](https://stackoverflow.com/questions/152555/h-or-hpp-for-your-class-definitions) – Gaurang Tandon Feb 12 '19 at 09:23

1 Answers1

19

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

Community
  • 1
  • 1
James McDonnell
  • 3,600
  • 1
  • 20
  • 26