在xxxx.h文件中使用extern声明变量: extern int i; 在xxxx.cpp文件中定义变量: int i; 声明和定义都只需一次。 转载于:https://www.cnblogs.com/2018shawn/p/9848055.html