Scenario A :
在一个头文件中都有staic int a=9; 然后,此头文件被多个cpp文件包含,不会报错,因为static的变量具有文件作用域。如果去掉static,则报错重复定义错误了。
Scenario B:
在a.cpp中定义两个全局变量:
static int gStaticA = 8;
int gNostaticA = 9;
然后,在另一个cpp文件中可以通过extern int gNostaticA;来使用a中定义的该变量; 但是不能extern int gStaticA,直接报link找不到的错误。
----
Ref:
https://blog.csdn.net/mary19920410/article/details/69053361