|
-
April 7th, 2009, 05:42 PM
#1
about #define
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
-
April 7th, 2009, 08:34 PM
#2
Re: about #define
Code:
#ifndef HEADER_NAME_H
#define HEADER_NAME_H
// ...
#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.
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|