我在头文件中定义了如下结构和结构对象:
struct STConfigurationDetails
{
bool bAutoStart;
bool bAutoLog;
bool bAutoScan;
bool bAutoMount;
bool bAutoOpen;
bool bAutoDetectLast;
};
struct STConfigurationDetails g_objConfigurationDetails ;
在头文件中,我自己就有了方法和方法体,它们都使用了g_ObjConfigurationDetails。当我将头文件包含到另一个cpp文件中并调用该方法时,这样做很好。但当我将头文件添加到另一个cpp文件时,我得到了错误:
错误1错误lnk2005:“struct stconfigurationdetails g_objconfigurationdetails”(?已在ndsclientdlg.obj ndsconnectdlg.obj ndsclient中定义了g_objconfigurationdetails@@3USTConfigurationdetails@@a)
错误2致命错误LNK1169:找到一个或多个多重定义的符号d:\fromclearcase\development\nds_\exe\debug\ndsclient.exe 1 ndsclient
在搜索了几条线程之后,我发现我必须声明我的对象是静态的,并且解决了这个问题。但我想知道为什么在只在头文件中创建实例时出现多个实例错误。
这是因为我的头文件有一个全局变量,并且它包含在多个CPP中吗?