This is a really good question, and it all comes down to compilation times. People from von .NET face some difficulties understanding the difference between #include
and, for example. C # using
. What you need to keep in mind:
The #include
directive copies the contents of an attached file.
Thus, if you put the implementation code in your header, you essentially compile it several times, once on each #include
site (and the linker will have to remove the duplicate code). In addition, if you modify the cpp file, it will be recompiled alone. If you change the header file, all files, including it (also indirectly!), Will be recompiled.
So put as many internal implementation files (i.e. cpp) as possible . Compilers have become quite good, since optimizing the time code of links, the fact that this can prevent inlining is less of a problem than before.
This is not possible with templates, and this explains most of the very long compilation periods that you can see when using C ++.
source share