Why is LINK2005 error: the error already set by the object disappears when I declare the object static

I have the following structure and structure object defined in the header file, as shown below:

struct STConfigurationDetails
{
    bool bAutoStart;
    bool bAutoLog;
    bool bAutoScan;
    bool bAutoMount;
    bool bAutoOpen;
    bool bAutoDetectLast;
};

struct STConfigurationDetails g_objConfigurationDetails ;

In the header file, I have both the body of the method and the method that uses g_objConfigurationDetails. This works fine when I include the header file in another cpp file and call the method. But as soon as I added the header file to another cpp file, I got an error:

Error 1 error LNK2005: "struct STConfigurationDetails g_objConfigurationDetails" (? G_objConfigurationDetails @@ 3USTConfigurationDetails @@ A) already defined in NDSClientDlg.obj NDSConnectDlg.obj NDSClient

2 LNK1169: d:\FromClearCase\Development_view\NDS_11152010\exe\Debug\NDSClient.exe 1 NDSClient

, , . , , te.

, CPP?

+3
3

static , . CPP , . extern , CPP, .

static, , CPP . , . .

, ​​ CPP , ( extern) , CPP. , , . . extern.

+4

, . , .cpp , , . , static, .cpp , .

static, .cpp , , , .

, , /, , , .cpp .

+3

Global static variables have an internal relationship .

0
source

Source: https://habr.com/ru/post/1774902/


All Articles