| 122 | |
| 123 | === Use forward declarations === #code-good-bad-limits-forward-declarations |
| 124 | |
| 125 | Whenever possible __use forward declarations__ in header files. They are ''vital in reducing compilation times''. Remember that the preprocessor first compiles every include into the file subsequently served to the compiler. The larger this file becomes, the longer compilation takes. |
| 126 | |
| 127 | If a function defined in a header file just has the parameter as a reference or as pointer, don't add the include but only the forward declaration in the header file. |
| 128 | {{{ |
| 129 | // some header file |
| 130 | |
| 131 | class MightyClass; |
| 132 | |
| 133 | class SmallClass { |
| 134 | ... |
| 135 | void foo(MightyClass &_m); |
| 136 | ... |
| 137 | }; |