Click here to Skip to main content
15,885,244 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
SuggestionRe: Comboboxx issue in MFC Pin
Richard MacCutchan3-Dec-15 3:50
mveRichard MacCutchan3-Dec-15 3:50 
QuestionVisual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Javier Luis Lopez26-Nov-15 0:09
Javier Luis Lopez26-Nov-15 0:09 
AnswerRe: Visual Studio errYou should declare it or LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan26-Nov-15 0:24
mveRichard MacCutchan26-Nov-15 0:24 
GeneralRe: Visual Studio errYou should declare it or LNK2005: variable XXX redefined in xxx.obj Pin
Javier Luis Lopez26-Nov-15 0:53
Javier Luis Lopez26-Nov-15 0:53 
GeneralRe: Visual Studio errYou should declare it or LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan26-Nov-15 1:11
mveRichard MacCutchan26-Nov-15 1:11 
GeneralRe: Visual Studio errYou should declare it or LNK2005: variable XXX redefined in xxx.obj Pin
Javier Luis Lopez26-Nov-15 3:29
Javier Luis Lopez26-Nov-15 3:29 
GeneralRe: Visual Studio errYou should declare it or LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan26-Nov-15 4:26
mveRichard MacCutchan26-Nov-15 4:26 
AnswerRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Daniel Pfeffer26-Nov-15 6:34
professionalDaniel Pfeffer26-Nov-15 6:34 
Another way to solve this problem (and have only one place where the variable is defined):

In foo.h:
C++
#ifdef DEFINE_GLOBALS
#define GLOBAL
#define INIT(x) = (x)
#else
#define GLOBAL extern
#define INIT(x)
#endif

GLOBAL int globalInt INIT(42);


In foo.cpp (and ONLY in foo.cpp):
C++
#define DEFINE_GLOBALS
#include "foo.h"


In other source files:
C++
#include "foo.h"

If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.

--Winston Churchill

GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
CPallini26-Nov-15 21:09
mveCPallini26-Nov-15 21:09 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan26-Nov-15 22:23
mveRichard MacCutchan26-Nov-15 22:23 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Daniel Pfeffer28-Nov-15 6:51
professionalDaniel Pfeffer28-Nov-15 6:51 
AnswerRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
«_Superman_»29-Nov-15 18:46
professional«_Superman_»29-Nov-15 18:46 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan29-Nov-15 22:22
mveRichard MacCutchan29-Nov-15 22:22 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
«_Superman_»29-Nov-15 23:07
professional«_Superman_»29-Nov-15 23:07 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan29-Nov-15 23:38
mveRichard MacCutchan29-Nov-15 23:38 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
«_Superman_»29-Nov-15 23:40
professional«_Superman_»29-Nov-15 23:40 
GeneralRe: Visual Studio error LNK2005: variable XXX redefined in xxx.obj Pin
Richard MacCutchan30-Nov-15 0:01
mveRichard MacCutchan30-Nov-15 0:01 
Questionc langugae Pin
ravi siriki23-Nov-15 1:58
ravi siriki23-Nov-15 1:58 
AnswerRe: c langugae Pin
David Crow23-Nov-15 2:38
David Crow23-Nov-15 2:38 
QuestionQuestion about malloc a struct Pin
Millenia Nova20-Nov-15 16:02
Millenia Nova20-Nov-15 16:02 
AnswerRe: Question about malloc a struct Pin
Jochen Arndt20-Nov-15 21:45
professionalJochen Arndt20-Nov-15 21:45 
GeneralRe: Question about malloc a struct Pin
Millenia Nova21-Nov-15 21:53
Millenia Nova21-Nov-15 21:53 
GeneralRe: Question about malloc a struct Pin
Jochen Arndt22-Nov-15 0:22
professionalJochen Arndt22-Nov-15 0:22 
PraiseRe: Question about malloc a struct Pin
Millenia Nova22-Nov-15 11:12
Millenia Nova22-Nov-15 11:12 
AnswerRe: Question about malloc a struct Pin
Richard MacCutchan20-Nov-15 21:45
mveRichard MacCutchan20-Nov-15 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.