   Anyone able to explain how to use these?
  I have a book that when it talks about composite classes it mentions having special statements at the top of your header files so that one class isn't trying to find another class (or something to that effect, the book isnt very clear and neither is anything I found online)Here are the statements, if anyone is able to clarify how to use them and what exactly they do I would greatly appreciate it.#indef _NEWFILE_H    #define _NEWFILE_H#endif /* _NEWFILE_H */Why would the book comment out the #endif? Is the comment just for reference?I tried implementing this with my headerfile names but got nothing but errors. Say I have a base MonsterClass, a derived BattleMonsterClass, and a composite of the two, BossMonsterClass. How would I implement these tags? I have no problems with the program compiling and it runs fine without them but I have a feeling this is something I may need in the future.   
  The #endif isn't commented out (the comment comes after the macro). Also, although it's fairly common to see such macros prefixed with underscores, it's best to avoid this, since symbols that are prefixed with underscores (and that meet a few other criteria that I won't go into here) are reserved by the implementation.As for the purpose of these macros, Google 'header guards' and you'll probably find a decent explanation. In short though, header guards ensure that the content of the header is included only once per translation unit (without this safeguard you would likely run into 'multiple definition' errors at some point).   ;  First of all it is #ifndef, not #indef.  What is means is "if not defined".So if the the following is not defined, then do the # preprocessor if statement.  That statement defines the value, so that way for the rest of the compile this header is only included once.  No matter what order things are processed the first time it runs across this it gets defined and won't keep rereading the header giving you tones of redefines.The #endif just ends the statement and needs to be the last non-commented statement in your file.  The /* */ is not commenting out your directive, it is after it.theTroll   ;  The comment to the right of #endif is indeed just for reference, so you can easily remember what if statement it refers to.Anyway, this technique from the book is called an "include guard."Let's say you have 3 header files: A.h, B.h and C.h. If both B.h and C.h need to include A.h in order to compile, you'll want to include A.h in both, but overall, in your project, you just want A.h to be processed once, otherwise you'll get redefinition errors. So doing this ensures that A.h will only be included once.This is not necessary, usually, if you know in advance the order of includes.For instance, if you do this in your main header file:#include "A.h"#include "B.h"#include "C.h"You won't really need to include A.h in B and C, since the order is fine as it stands. But if you need to reuse B.h later on, or someone else needs to use it, it can be very helpful to be able to include just B.h and have it include A.h automatically.This example is overly simplistic of course, so to really grasp the usefulness of include guards, imagine a complex tree of header files that include each other over several levels -- some of them might include the same headers, others might need to include stuff on several levels, and you might not always know which headers need to be included. With include guards, you just include what you need, and the dependencies are already figured out for you.In MS visual studio, there's a compiler directive you can use instead of ifndef/endif: just put #pragma once at the top of your header file, it'll have the same effect.   ;  Thank you for the advice guys :) However I am still a little confused after googling and reading the comments. Let me see if I have this correct:I have three header files: A.h, B.h, and C.h.A.h is my base classB.h is a derived class of AC.h is a composite class of A and Bso for A class I would write://nothing because its the base classfor B class I would write:#ifndef A.h#define A.h#endif //A.hand for C class I would write:#indef A.h#define A.h#endif //A.h#indef B.h#define B.h#endif //A.hI am assuming that I use the include guards to include whatever file may be necessary to run the header file in question. Am I correct in this?   ;  In the example, A.h, B.h, and C.h denote header files, not classes. Classes are typically (but not necessarily) declared inside header files, but also other stuff may be declared therein. During compilation (which is done in so-called "compilation units" to avoid to compile each and every part if just one of them is altered) one has to make all necessary declarations known to the particular compilation unit. So one needs to include the one or other header file within the implementation file (those ending on .cc or .cpp or .c++ or whatever) or other header files. So it is in principle possible to include a header file twice, e.g. in this situation:file A.hfile B.h includes A.hfile A.cpp includes A.h and B.hThen the compiler will complain that the stuff declared inside A.h will be re-declared, and compilation will break. To avoid this header files are to be protected by inclusion guards (if the programming language / compiler doesn't support something else).To your example: File A.h#ifndef A_H#define A_H// declarations of A goes here#endifFile B.h#ifndef B_H#define B_H#include "A.h"// declarations of B goes here#endifFile C.h#ifndef C_H#define C_H#include "A.h" // not really necessary, due to already done indirectly by the next line#include "B.h"// declarations of C goes here#endif;  OH ok I get it now. This makes sense. When I get some free time today I will implement these into my practice programs. Thank you all for your help :)One last question:What exactly does the compiler look for? I see examples online that use _A_H and others that use A_H (although a previous poster said not to use underscores so I wont).Does the compiler only look for the header file name? Usually everything in C++ has to be exact.   ;  Actually it doesn't matter at all what you use (as long as there are no spaces), the complier does not care at all.theTroll   ;  You have to keep in mind that the symbol is unique under all circumstances when compiling the project. That means you must not use a symbol that is already used in any other included files, may it yours or from a 3rd party file you're working with. Due to this, using the current file name (but substituting all unallowed chars e.g. with an underscore), perhaps augmented with the project's name, is good practice.   ;  Oh I think I get it (sorry this is taking so long)The statement:#ifndef B_H //if not defined, B_H#define B_H //This says "make this file B_H"?#endifIs for the B.h header file, so if I wanted, I could make this say#ifndef Scott_h#define Scott_h#endifAnd it would still work because the #define statement says that the B.h header file has that name Scott_h attached to it. So I could theoretically name it whatever I want as long as I am using no illegal characters. Is this correct?[Edited by - Chrono1081 on April 18, 2008 7:28:26 AM]