A few reasons:
(1) Incremental build times
When projects grow, managing build time is problematic, especially for C ++ projects. Building 1 or 5 minutes after minor changes is of great importance. This is underlined by most of the changes in large projects, which are small and require a lot of testing. Add to that any TDD attempt and refactoring, and you are dead slime with Sicilian shoes.
Separating the header and body and moving it to libs significantly increases the incremental build time.
(2) Statics
For many things, you need one type instance, i.e.
There is no way (what I know) that allows this in the project for header only. Specific solutions for the compiler are limited, for example. __declspec(selectany) in MSVC is limited to POD types.
(3) Hiding implementation
.cpp / .h is the only way to clearly separate the public interface from implementation details. You can move class members to the private section, but this does not work for other objects. (Even the header / body separation is leaky if you do not add additional methods such as PIMPL, so this argument is a bit weak IMO, but again, in a large project, I would very much miss this effective if imperfect method).
Great question, anyway, you admitted that there is something unpleasant with the C / C ++ assembly model, which I consider an ancient relic of terrible consequences.
You should try how far you can push the heading-only model (or at least βheading-onlyβ to allow static). You could get pretty far - it would also be interesting to hear from people who have tried.
Perhaps you should try using static libraries to separate and encapsulate implementations, and otherwise save all your code in headers. I see some problems with this, but it is not that our current modus operandi is not possible.
peterchen
source share