我在头文件中定义了下面的结构和结构对象,如下所示:为什么错误LINK2005:当我将对象声明为静态时,对象已定义的错误消失
struct STConfigurationDetails
{
bool bAutoStart;
bool bAutoLog;
bool bAutoScan;
bool bAutoMount;
bool bAutoOpen;
bool bAutoDetectLast;
};
struct STConfigurationDetails g_objConfigurationDetails ;
在头文件中,我自己拥有使用g_objConfigurationDetails的方法和方法体。当我将头文件包含到另一个cpp文件并调用该方法时,这工作正常。但是当我将头文件添加到另一个cpp文件时,我得到了错误:
Error 1 error LNK2005: "struct STConfigurationDetails g_objConfigurationDetails" ([email protected]@[email protected]@A) already defined in NDSClientDlg.obj NDSConnectDlg.obj NDSClient
Error 2 fatal error LNK1169: one or more multiply defined symbols found d:\FromClearCase\Development_view\NDS_11152010\exe\Debug\NDSClient.exe 1 NDSClient
在搜索了几个线程后,我发现我必须将我的对象声明为静态并且它已经解决了。但我想知道为什么在我只在te头文件中创建实例时出现多个实例错误。
这是因为我的头文件有一个全局变量,它被包含在多个CPP中?