A preprocessing function used by C + + programs is a header file protector, and the header file protector relies on preprocessing variables. There are two types of preprocessing variables: defined and undefined, #define指令把一个名字设定为预处理变量, and the other two directives check whether a given preprocessing variable is already defined: #ifdef当且仅当变量已定义的时候为真, #inndef当且仅当变量未定义时为真. Once the check results are true, follow-up operations are performed until #endif is encountered.
These features can be used to effectively prevent duplicate inclusions from occurring:
#ifndef Sales_h #define Sales_h ... #endif
When a Sales.h is included for the first time, #ifndef的检查结果为真, the preprocessor performs the subsequent operation sequentially until #endif is encountered. At this point, the value of the preprocessing variable sales_h becomes defined, and the Sales.h is copied into the program. If you include Sales.h again later, the #ifndef check result is false, and the compiler ignores the part between #ifedef and #endif.
C + + Prime: Preprocessor