Some notes on #ifndef   #define   #endif




Suppose you have:

file.h:

#ifndef FILE_H
#define FILE_H

class FileClass {
public:
  int x;
}

#endif

When the compiler sees for the first time, #ifndef FILE_H, since it
hasn't seen FILE_H (that is: FILE_H is undefined, think of it as
having value zero), it then proceeds into the if statement, (ifndef
stands for if-not-defined).  The next line defines FILE_H, since it
was undefined (in other words, sets FILE_H = 1).  FILE_H is basically
some globally unique variable name, that should be related in some way
to the file using it.  The compiler then includes everything from
there until the #endif into the compilation processs.  If you then
had two .cpp files that both had the line:  #include "file.h" 
file.h would only be included once, because the second time the
compiler got to the #include "file.h" line, it would have 
defined FILE_H, and so the file would only be included once.
This prevents circularities if for example you had #include "file2.h"
inside file.h, and #include "file.h" inside file2.h.

Check out the slides from section E, for a little more on this.

http://www.cs.washington.edu/education/courses/cse143/CurrentQtr/slides/e-class
es.pdf


You don't have to really worry about this, it's just another good
thing to put in a header file to prevent compilation problems.
For example, on the next homework assignment you may want to
put it in any header files you create.