What is the difference between a .cpp file and a .h file?
The C++ build system (compiler) knows no difference, so it's all one of conventions.
The convention is that .h
files are declarations, and .cpp
files are definitions.
That's why .h
files are #include
d -- we include the declarations.
The .cpp
file is the compilation unit: it's the real source code file that will be compiled (in C++).
The .h
(header) files are files that will be virtually copied/pasted in the .cpp
files where the #include
precompiler instruction appears. Once the headers code is inserted in the .cpp
code, the compilation of the .cpp
can start.