Yesterday I read the pen questions of Xintai technology.
The first feeling is that the foundation for the next session is too poor.
Then I found an interesting question: how to use C ++ global variables in other CPP files?
My first thought was to use it directly. However, I feel that it is better to add "include" and ":". By the way, I asked people who are sleeping in the same room. I found that the answer was completely different. He said that we had to add extern to every CPP, and we were stuck. So we started vs2005 and started programming verification. Then we found that if it is a CPP file, how to do it is correct. If there are two or more CPP files, the correct format is as follows:
OO. h
# Ifndef oo
# Define oo
Extern int A; // note that values cannot be assigned here.
# Endif
OO. cpp
# Include <iostream>
Using namespace STD;
Int A = 10; // defines the variable.
Void func () {A = 20; cout <;}
XX. cpp
# Include <iostream>
# Include "Oo. H"
Using namespace STD;
Int main ()
{
Cout <A; // here, a prints 10, which indicates that a = 10 in OO. cpp is executed first.
Func ();
}
This seems to be a correct practice. I don't know if there are other practices.