定义全局变量时,以下面为例:
一个工程有part.h part.cpp main.cpp三个文件
其中后两个文件都包含前面的头文件,则不要在part.h中定义变量,这样会出现重复定义,较好的做法是定义全局变量。
part.h中:extern int a;
part.cpp中:int a;
main.cpp中就不要在定义了.
定义全局变量时,以下面为例:
一个工程有part.h part.cpp main.cpp三个文件
其中后两个文件都包含前面的头文件,则不要在part.h中定义变量,这样会出现重复定义,较好的做法是定义全局变量。
part.h中:extern int a;
part.cpp中:int a;
main.cpp中就不要在定义了.