You do not repeat. You write code only once in one header. It is repeated by the preprocessor, but this is not your problem, and this is not a violation of DRY.
If this is correct for templates, why not for regular classes
This is not exactly what you need to do for templates. This is the only one that really works as a whole.
In any case, if you implement the class in the header, you get the following advantages and disadvantages:
- The full implementation is visible wherever it is used, which simplifies assembly if necessary.
- The same code will be analyzed and compiled several times, which will lead to higher compilation times.
- On the other hand, if everything is in the headers, this can lead to fewer translation units, so the compiler should work fewer times. Ultimately, you can get a single translation unit, which includes only once, which can lead to very fast compilations.
And ... what is it really.
Most of my code tends to be in the headers, but that is because most of my code is templates.
jalf Nov 23 '09 at 16:21 2009-11-23 16:21
source share