Modules - itzjac/cpplearning GitHub Wiki

The whole purpose of header files makes sense when the program is designed to be modular and be architected through several different compile units.

When an specific module wants to be reused in other different modules that are in a different compile unit, the header will provide one single entry point to access the features, this is what's fomally called the One Definition Rule (The C++ Programming Language, Bjarne Stroustrup).

ModuleA.h

ModuleB.cpp ModuleC.cpp

If the ModuleA, is intended to be used in both ModuleB/C, the only way to share that common data between different compile units is through the declaration in the headers. Otherwise, we would end up writing a program that only works as Unity build (one compile unit for the entire program), when working with large teams, we would generally want to avoid that.

But really, if the Unity build mode is the only used and you are probably a solo coder, then headers have less meaning and the single compilation unit can handle most of the cases without a header, but be aware that you will definitely loss the reusability context.