C++下的全局变量的定义和使用出错,请教!
zzol 2005-03-23 04:14:43 我想定义一个全局变量,是在一个类的头文件中定义的:
double test1=50;
double test2=20;
class CInput : public CDialog
{
………………
}
通过这个类对这两个变量进行更新数值,
在另外类中使用test1;test2的数值
extern double test1;
extern double test2;
但是如果有多个类使用test1和test2就会出错:
MainFrm.obj : error LNK2005: "double test2" (?test2@@3NA) already defined in Input.obj
MainFrm.obj : error LNK2005: "double test1" (?test1@@3NA) already defined in Input.obj
Output1.obj : error LNK2005: "double test2" (?test2@@3NA) already defined in Input.obj
Output1.obj : error LNK2005: "double test1" (?test1@@3NA) already defined in Input.obj
这样做的问题出在哪里?