写的一个程序在bulid时发生了错误是全局变量的重复定义。我的做法是把全局变量在globalVars.h中定义,然后再每个要用的文件里包含该头文件,并把要用的加extern声明。
如globalVars.h
#ifndef GLOBALVARS_H
#define GLOBALVARS_H
const int MaxN = 100;
const double PI = 3.14159265;
const int iniHigh = 400 ;
const int iniWidth = 576 ;
const int perHour = 10;
ctyInf g_city[MaxN];
int g_city_num;
#endif // GLOBALVARS_H
inputblock.cpp:
#include "functions.h"
#include "dataStruct.h"
#include "globalVars.h"
#include <QtGui>
#include <cstring>
#include <cstdlib>
#include <ctime>
extern ctyInf g_city[MaxN];
extern int g_city_num;
错误是:
E:/DS/travelSys/inputBlock.cpp:39: multiple definition of `g_city_num'
E:/Qt/QtCreator/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/locale_facets.tcc:2497: multiple definition of `g_city'
请问这该怎样处理?