I get the impression (from previous posts) that when working with large numbers of header files, the coder should always include header "guards" to keep them from being included more then once. Header guards being the ("ifndef HEADER_H ....stuff). This is something that I have not been doing, and I am constantly getting redefinition errors.
Code:
#ifndef __yourheader_h__
#define __yourheader_h__
//all your code goes here
#endif
A few questions about this:
(1) Is this the best way to avoid having classes included multiple times (thus causing errors)?
(2) Is this techinique "Good Coding Practice" or is it a "work around"...ie are you guru's doing this too?
Formating questions:
(1) if the header file that I am creating also needs to "#include" other classes, does it matter if I do that before the "#ifndef" guard statement or after?
(2) Does the name that I used in the #ifndef _HEADERNAME_H matter (ie. do I have to use underscore, or can I just use the class name?)
(3) I have also seen this technique (below) online...when/how (if ever) should I use this?
Code:
#ifndef _HEADERFILE_H
#include "HeaderFile.h"
#endif
Thanks for your help