Hi, all
I have a question about the following header file
I don't understand why #define is used
Does anyone know what's the purpose of it?
Thanks
Kai
// Kai.h
#ifndef KAI_CLASS1_H
#define KAI_CLASS1_H
namespace Kai
{
class class1 {
...
} ;
}
#endif
Printable View
Hi, all
I have a question about the following header file
I don't understand why #define is used
Does anyone know what's the purpose of it?
Thanks
Kai
// Kai.h
#ifndef KAI_CLASS1_H
#define KAI_CLASS1_H
namespace Kai
{
class class1 {
...
} ;
}
#endif
Those are things that are added to header files to avoid re-definition of its contents. It is a convention now to add that every single time you create a header file.Code:#ifndef HEADER_NAME_H
#define HEADER_NAME_H
// ...
#endif
Suppose you have a file A.cpp that includes a file B.h at the start of a program (or anytime). Then later on a file C.cpp also includes that file B.h.
What will happen in this case? "Compiler error! Redefinition of xxx & xxx & ..."
Those headers prevent that from happening.