首先ifndef/define/endif是用来管理头文件的就是.h文件
先来个例子
#ifndef _FIST_H_ //如果定义了fist.h文件则跳转至 endif 结束定义
#define _FIST_H_ //定义fist.h文件
...
#include <second.h> //定义second.h文件
...
#endif
看了例子大家可能就明白了语法的意思了,但是你可能不知道为什么要这么定义????
/* test.cpp*/
#include <fist.h>
#include <second.h>
······
/* fist.h*/
#include <second.h>
······
/* second.h*/
#include <fist.h>
你写的test.cpp里包含了fist.h和second.h,fist.h里包含了second.h,**second.**h里包含了fist.h,所以fist.h,second.h就会循环包含,预处理阶段就会不停地循环展开头文件。
这时候使用ifndef/define/endif就可以避免重复定义了,因为当ifndef会在判断fist.h被定义,如果定义就很直接跳出去了。