我有两个需要访问公共变量的源文件.做这个的最好方式是什么?例如:
source1.cpp:
int global;
int function();
int main()
{
global=42;
function();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
source2.cpp:
int function()
{
if(global==42)
return 42;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
变量global的声明是静态的,extern还是应该在两个文件包含的头文件中?
c++ ×1