c++多个源文件访问同一个全局变量

分为3步:html 1.在A.cpp 中声明:htm extern int a;blog 2.在A.cpp【注意和上面A.h对应】中定义:get int a;编译 或变量 int a=0;\static   3.在其余源文件中直接访问便可文件 c.cpp中:vi a=10;co     若是在A.h中定义 int a;在b.cpp和c.cpp中include “A.h" 会报重定义的错 若是在A.
相关文章
相关标签/搜索