我在頭文件中定義了下面的結構和結構對象,如下所示:爲什麼錯誤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中?