How to avoid duplicate definition of it when you define global variables in C ++? As long as far as possible in the .cpp file in the definition, and not defined in the .h file, define good after, you can use the keyword extern in the .h file statement.
If the definition in the .h file, then it could cause a multi-layer contains a double definition error. The following shows an example for everyone through.
Define global variables in the base.cpp
Base.cpp
int g_MaxTime;
int g_MinTime;
int g_MaxCount;
int g_MinCount;
base.h
extern int g_MaxTime;
extern int g_MinTime;
extern int g_MaxCount;
extern int g_MinCount;
Then when the other files you want to use these variables
As long as #include "base.h" on it, and will not cause a double definition error
-------------------------------------------------------------------------------------------
Original: https: //blog.csdn.net/u013015629/article/details/52911398