As far as I know, .cpp usually contains far more codes than .h, mainly because .cpp contain implementation details of functions instead of just one line of class member/method definition.
Here comes to my mind is a quite weird idea: is it good practice to write or migrate some contents or codes from .cpp to .h, in order to reduce the amount of codes in .cpp?
I know we should not write everything in header in order to:
Prevent extra compile time when recompiling codes after content is changed in the header
Prevent include one header from another header which is not necessary for every compile unit (i.e.:prevent header spaghetti)
but I think some contents can be moved to header "safely", such as function documentation and functions that fulfilling all conditions below:
Rarely changed functions
Simple or trivial functions (e.g.:setters and getters)
Functions that does not lead to extra include statements in cpp
and the bonus advantage of moving functions to headers is we can declare those functions as inline which gains extra performance improvements.
Is it a good practice to narrow the line number difference between header and corresponding .cpp files?
inline
. As headers are usually included more than once, any definition there would violate the ODR if notinline
. As for actual inlining, that doesn't require they keywordinline
.