C++定义全部变量注意项

1. 使用extern 

在.h头文件中声明,如 extern int x;

在.cpp源文件中定义,int x=1.

2. 使用static

一般在.cpp源文件中声明和定义,防止模块间信息污染。

如 static int x=1;

static和extern不能同时修饰同一个变量。

原文地址:https://www.cnblogs.com/nora/p/7151166.html