I have two source files that need to access a common variable. What is the best way to do this? e.g.:
source1.cpp:
int global;
int function();
int main()
{
global=42;
function();
return 0;
}
source2.cpp:
int function()
{
if(global==42)
return 42;
return 0;
}
Should the declaration of the variable global be static, extern, or should it be in a header file included by both files, etc?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…