how come this happen? thank you
-
I build a dialog based MFC program. in the file "StdAfx.h" I add the following code,which is used to define a global variable of type
CString
.#ifndef jjjjjjjjjjjjjjjjjjj
#define jjjjjjjjjjjjjjjjjjj
CString StrGlobal;
#endifand then I use it in another file "newfile.cpp"
#include "stdafx.h"
extern CString StrGlobal;
void fun()
{
StrGlobal = _T("KDKDK");
}when I build the program, following link error shows up: Linking... StdAfx.obj : error LNK2005: "class CString StrGlobal" (?StrGlobal@@3VCString@@A) already defined in newfile.obj why dose this happen? and how can I fix it ? Thank you very much!!! ------------------- I am learning C++ and English
-
I build a dialog based MFC program. in the file "StdAfx.h" I add the following code,which is used to define a global variable of type
CString
.#ifndef jjjjjjjjjjjjjjjjjjj
#define jjjjjjjjjjjjjjjjjjj
CString StrGlobal;
#endifand then I use it in another file "newfile.cpp"
#include "stdafx.h"
extern CString StrGlobal;
void fun()
{
StrGlobal = _T("KDKDK");
}when I build the program, following link error shows up: Linking... StdAfx.obj : error LNK2005: "class CString StrGlobal" (?StrGlobal@@3VCString@@A) already defined in newfile.obj why dose this happen? and how can I fix it ? Thank you very much!!! ------------------- I am learning C++ and English
You've got the
extern
in the wrong file: It should be in the .h file. Steve