+ 1
.cpp and .hpp
What will happen if we put both definitions and declarations in .hpp in c++? Overall whatâs the difference between .cpp and .hpp file ?
5 RĂ©ponses
+ 3
.hpp or just .h is used as header, which means that you should only declare all functions and classes in it, so the compiler can link them correctly in case you want to access the document from your main program file:
// print.hpp
void print(int);
.cpp files now define the functions and classes you previously declared in the .hpp file:
// print.cpp
#include "print.hpp"
void print(int num) {
cout << num << endl;
}
If you just use a single file this doesn't matter, but working with multiple files can be really nice. In this case for example, you can now include the "print.hpp" file which will work just like a library, so you can call the print() function from your main source file.
+ 6
ShortCode connection issues, sololearn has poor servers
+ 1
.hpp is a header file, such like .h in C
.cpp runs the main program
0
á á brains posted it twice