Click here to Skip to main content
15,913,669 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionActiveX C++ component for printing? Pin
TigerNinja_5-May-04 7:43
TigerNinja_5-May-04 7:43 
GeneralProper way to define global class objects Pin
georgiek505-May-04 7:34
georgiek505-May-04 7:34 
GeneralRe: Proper way to define global class objects Pin
David Crow5-May-04 7:55
David Crow5-May-04 7:55 
GeneralRe: Proper way to define global class objects Pin
georgiek505-May-04 8:38
georgiek505-May-04 8:38 
GeneralRe: Proper way to define global class objects Pin
Rick York5-May-04 10:40
mveRick York5-May-04 10:40 
GeneralRe: Proper way to define global class objects Pin
Antti Keskinen5-May-04 10:49
Antti Keskinen5-May-04 10:49 
GeneralRe: Proper way to define global class objects Pin
Anonymous5-May-04 11:40
Anonymous5-May-04 11:40 
GeneralRe: Proper way to define global class objects Pin
David Chamberlain6-May-04 6:03
David Chamberlain6-May-04 6:03 
I generally find it problematic to put variable declarations (as opposed to definitions) into header files. The tricks suggested about using #ifdef... are really just to trick the compiler into accepting a generally ill-advised way of writing code.

My suggestion is to declare your global variables in the source file where they are originally created, not in a header file, and then every other source file that needs access to the global variables needs to use extern. For these other source files, they can #include a GlobalVars.h file that simply contains all of the necessary extern statements for the global variables. The main source file does not #include GlobalVars.h, as it is the file that is declaring them.

The advantage to this approach is that variables (and the access to them) is not hidden through a set of #include, #define, and #ifdef statements. You are writing exactly what you want in a straightforward way that will be less prone to error and easier to understand.

While it makes no difference to the compiler, it will be more understandable to anyone reading the code.

Dave



"You can say that again." -- Dept. of Redundancy Dept.
GeneralInvoking BIOS and DOS INT's Pin
Tank_Aviator5-May-04 7:18
Tank_Aviator5-May-04 7:18 
GeneralRe: Invoking BIOS and DOS INT's Pin
Jeremy Falcon5-May-04 7:35
professionalJeremy Falcon5-May-04 7:35 
GeneralRe: Invoking BIOS and DOS INT's Pin
David Crow5-May-04 7:44
David Crow5-May-04 7:44 
GeneralRe: Invoking BIOS and DOS INT's Pin
Paul Ranson5-May-04 8:44
Paul Ranson5-May-04 8:44 
GeneralRe: Invoking BIOS and DOS INT's Pin
Mike Dimmick5-May-04 12:44
Mike Dimmick5-May-04 12:44 
GeneralRe: Invoking BIOS and DOS INT's Pin
Alexander M.,6-May-04 7:24
Alexander M.,6-May-04 7:24 
GeneralMaking VC++ 6.0 projects out of VS.NET projects Pin
David Wulff5-May-04 7:15
David Wulff5-May-04 7:15 
GeneralRe: Making VC++ 6.0 projects out of VS.NET projects Pin
Chris Meech5-May-04 7:25
Chris Meech5-May-04 7:25 
GeneralRe: Making VC++ 6.0 projects out of VS.NET projects Pin
David Wulff5-May-04 7:28
David Wulff5-May-04 7:28 
GeneralPixel Processing Pin
cristane5-May-04 6:59
cristane5-May-04 6:59 
GeneralRe: Pixel Processing Pin
ocapic5-May-04 10:09
ocapic5-May-04 10:09 
GeneralRe: Pixel Processing Pin
Christian Graus5-May-04 10:37
protectorChristian Graus5-May-04 10:37 
GeneralPlease help! Dynamically Creating a Doc/View in a Dialog Pin
Charlie Curtis5-May-04 6:33
Charlie Curtis5-May-04 6:33 
GeneralRe: Please help! Dynamically Creating a Doc/View in a Dialog Pin
Iain Clarke, Warrior Programmer6-May-04 5:16
Iain Clarke, Warrior Programmer6-May-04 5:16 
GeneralRe: Please help! Dynamically Creating a Doc/View in a Dialog Pin
Charlie Curtis14-May-04 13:00
Charlie Curtis14-May-04 13:00 
QuestionHow to send as fax? Pin
Filomela5-May-04 5:03
Filomela5-May-04 5:03 
AnswerRe: How to send as fax? Pin
Antony M Kancidrowski5-May-04 6:34
Antony M Kancidrowski5-May-04 6:34 

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.