Placing all code in the header, or including the cpp is exactly 100% the same thing. Of course both cases can only be done when using templates, otherwise you'll get symbol redefinition. When using templtes I ALWAYS place all code in a cpp then include it, because then I'll get a clean headers, only with declaration, and comments explaning everything. But there's a vey important issue when including a cpp
Originally Posted by CornedBee
In the h file I write
in the cpp I write
declarations, comments, whatever
This way each piece of code won't be analysed twice, and you can make sure the matching header has been included.
templated code, inline functions
- the part is compiled only when included from the h
during compilation, the directive #include "file.cpp" will be substituted by the contents of the cpp file, which is the same as placing all code in the h.
But again, it's up to style. I much prefer having clean simple, and commented headers (I believe that's their porpouse), than all code mashed together.
So you decide. This also applies to inline functions