Combining two programs into one

Pages: 12
What is .hpp? I never heard of that.
its a .h file with 2 extra letters. (no sarcasm here, that is what it really is).

it was sort of a c++ header file (instead of a C header file) differentiation effort that never really caught on. A few places used it and still do, most places use .h for C++ though.

most c++ compilers do not actually check the file extension. I used to force inline c++ code by #include "filename.inl" where the inline code would go. (force inline isnt as useful a thing anymore, it was at that time).

A few places dropped the extension and that works too. If you add the path to your project, you can have
#include <crap> and it works just fine assuming that crap is an extensionless text file with valid c++ header stuff in it and that its in the search path. I hate this, but people do it. The justification was to have it look like standard headers. I feel having them not look the same is much more informative.
Last edited on
C language code is usually in headers (.h) and sources (.c).
C++ language code is usually in headers (.h) and sources (.cpp), but some prefer to name their headers (.hpp).
C++ Standard Library has header files with no extension at all.
Generally speaking, it's not a good idea to take a source file and just include it as if it were a header file. (And, no, changing the name of the file so that it ends in .hpp instead of .cpp does not magically change that.)

The way to do this sensibly is to put the function declarations (i.e. prototypes) into header files, and include those. Then put the full definitions of those functions into source files, and link those into your project.

Also, never, ever, put using namespace statements into header files. Ever. It's dangerous.

What you've done here will work for a tiny beginner project, but it won't work the moment you start to make bigger ones. Avoid learning bad practises that will get you into trouble later.
Topic archived. No new replies allowed.
Pages: 12