1.在头文件中外部声明 例
在test.h中
extern bool flag;
在test.cpp中外部定义
#include <test.h>
bool flag = true;
在其他文件夹中调用方式则为
在test1.cpp中外部定义
#include <test.h>
bool flag = true;
此时,变量flag则为这三个文件中相同的变量,可在函数中重复使用或者赋值
参考https://blog.csdn.net/quzhongxin/article/details/45054823?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.add_param_isCf