#ifndef TEST_H
#define TEST_H
// code here
#endif
作用:防止文件中的内容被重复引用/定义
展开说说:即include嵌套,同一个头文件(.h)在同一个源文件(.cpp)中被include了多次。举个例子,在main.cpp源文件中include了“a.h”和“b.h”,但同时在a.h头文件中也include了“b.h”,此时,b.h就在一个源文件中被引用了两次,导致重复引用和定义。
#ifndef TEST_H 的意思是 if not def test.h,即如果不存在test.h这个头文件,则进行def,引入test.h,以及接下行的code,如果已经存在,则直接跳到 #endif。