In Cocos2d-x's D:\phoneclient\cocos2dxlib\cocos\base\CCValue.h file, the following code is found:
After the global lookup, in the D:\phoneclient\cocos2dxlib\cocos\base\CCValue.cpp file, locate the definition of the variable:
extern int a;//This is statement a
int a;//This is the definition of a
Under normal circumstances, the H declares the CPP definition.
declarations and definitions are different, declarations can be made more than once, and defined only once.
h files may be contained in a lot of CPP files, so only write declarations cannot write definitions, and if write definitions are included several times, they are defined several times.
The primary purpose of the conditional indicator #ifndef is to prevent duplicate inclusion and compilation of header files. A source file contains a number of the same header file, and will only be included once when multiple source files contain the same head file, each source file will be included once, the variables will be defined multiple times, link error.
Also, the concept of a C language, such as header files and precompiled macro #ifndef, is not related to the principle of compiling
Define variables in. cpp files, extern in. h files