Quote:Original post by Inmate2993
In your header files, protect the file from double inclusion by using preprocessor definitions.
*** Source Snippet Removed ***
*** Source Snippet Removed ***
However, if you want everything to work from a single include file, you have to do this:
*** Source Snippet Removed ***
*** Source Snippet Removed ***
Its one of many ways to do it.
I would just like to mention a game programming tip I picked up from a book - if you have a larger project, you will want to do the same thing with the #ifndef, but Also in the source files. This will cut down compile time a lot because instead of pasting the whole header file it will skip it.
Here is an example:
header1.h:#ifndef h1
#define h1
...
#endif
file1.cpp:#ifndef h1
#include "header1.h"
#endif
...
.....................
file999.cpp:#ifndef h1
#include "header1.h"
#endif
...
Instead of always pasting the entire header1.h file in every source file - then not even compiling it because it is already defined - you can use this method to only compile it once and include it once, thus saving a lot of compile time. One thing htey mentioned that is does look messy - but its valuable. You can also do the same thing for standard includes as well.
- Drew