C++ #ifndef #endif 条件编译

#ifndef  : if not defined

  是预处理功能(宏定义、文件包含、条件编译)当中的条件编译;

    1. 防止头文件的重复包含和编译

    2. 便于程序的调试和移植

#endif:

示例:

test1_h   test2_h

当test2_h文件中引入了 test1_h头文件

在Main.cpp文件中分别导入了 test1_h  test2_h文件 会爆出错误头文件重复定义

加入  #ifndef   #endif  解决此问题

posted on 2023-11-23 16:06  廿陆  阅读(54)  评论(0)    收藏  举报

导航