Include what you need and nothing more.
Including the same header file in multiple .h files and multiple .cpp files is not a problem in itself. Header protectors are effective in alleviating the problems of including files several times.
If you try to avoid including the same file several times, this can be negative, as this usually results in a βmega-inclusion fileβ that includes everything you need in the whole project. This is bad because a single change in any header file forces everyone to recompile.
If you are worried about the .h / .cpp file, including the same file, follow these guidelines:
- If you do not need to include a header in the file, include it only in CPP
- If a class declaration is required in the header file (but not used), use the formatted declaration in the .h file and include it in the CPP file.
- If you really use include in the header file, include it in the header file, not CPP.
source share