Click here to Skip to main content
15,892,537 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Dynamic array??? Possible??? Pin
Paul M Watt19-Mar-02 8:42
mentorPaul M Watt19-Mar-02 8:42 
AnswerRe: Dynamic array??? Possible??? Pin
Tomasz Sowinski19-Mar-02 8:49
Tomasz Sowinski19-Mar-02 8:49 
AnswerRe: Dynamic array??? Possible??? Pin
Nemanja Trifunovic19-Mar-02 8:49
Nemanja Trifunovic19-Mar-02 8:49 
AnswerRe: Dynamic array??? Possible??? Pin
dazinith19-Mar-02 9:00
dazinith19-Mar-02 9:00 
GeneralRe: Dynamic array??? Possible??? Pin
Christian Graus19-Mar-02 10:22
protectorChristian Graus19-Mar-02 10:22 
QuestionHow to create global variable? Pin
19-Mar-02 7:49
suss19-Mar-02 7:49 
AnswerRe: How to create global variable? Pin
Carlos Antollini19-Mar-02 7:51
Carlos Antollini19-Mar-02 7:51 
AnswerRe: How to create global variable? Pin
Paul M Watt19-Mar-02 8:07
mentorPaul M Watt19-Mar-02 8:07 
If you are not using MFC, then declare the variable in stdafx.cpp like you want it.

This block has been added to the original message to clarify some confusion.
My response was after Carlos' which was a response for MFC, his response was on the thread before this one. I added the statement about MFC just in to clarify that if the person who posted the question was not using MFC and could not use the CWinApp object. The technique that I posted will work for any type of C++ project.


int g_Temp;


Then you will need to declare it in stdafx.h like this:

extern int g_Temp;


The extern tells each file that it is included in to add the g_Temp variable to the symbol table so that the variable can be used, but does not actually allocate space for that variable in the obj file. Then when the linker comes around it will resolve all of the variable locations and what not.

If you do not use the extern keyword, and you declare the variable in the header, then your program will allocate space for each file that the variable was declared in, and when the linker tries to resolve all of the variable addresses, it will find collisions.
GeneralRe: How to create global variable? Pin
Tomasz Sowinski19-Mar-02 8:11
Tomasz Sowinski19-Mar-02 8:11 
GeneralRe: How to create global variable? Pin
Paul M Watt19-Mar-02 8:21
mentorPaul M Watt19-Mar-02 8:21 
GeneralRe: How to create global variable? Pin
Christian Graus19-Mar-02 10:24
protectorChristian Graus19-Mar-02 10:24 
GeneralRe: How to create global variable? Pin
Paul M Watt19-Mar-02 10:34
mentorPaul M Watt19-Mar-02 10:34 
GeneralRe: How to create global variable? Pin
Tomasz Sowinski19-Mar-02 10:43
Tomasz Sowinski19-Mar-02 10:43 
GeneralRe: How to create global variable? Pin
Christian Graus20-Mar-02 0:31
protectorChristian Graus20-Mar-02 0:31 
GeneralRe: How to create global variable? Pin
Bill Wilson19-Mar-02 14:03
Bill Wilson19-Mar-02 14:03 
GeneralRe: How to create global variable? Pin
Bill Wilson19-Mar-02 14:03
Bill Wilson19-Mar-02 14:03 
AnswerRe: How to create global variable? Pin
Tomasz Sowinski19-Mar-02 8:10
Tomasz Sowinski19-Mar-02 8:10 
GeneralSame caption problem as before, what am I doing wrong? (half reposted) Pin
generic_user_id19-Mar-02 7:48
generic_user_id19-Mar-02 7:48 
General_beginthreadex questions Pin
Le centriste19-Mar-02 7:39
Le centriste19-Mar-02 7:39 
GeneralRe: _beginthreadex questions Pin
Nemanja Trifunovic19-Mar-02 7:39
Nemanja Trifunovic19-Mar-02 7:39 
GeneralMore FlexGrid issues with .NET Pin
dazinith19-Mar-02 7:33
dazinith19-Mar-02 7:33 
GeneralCreating GDI Controls From Scratch Pin
alpha+19-Mar-02 6:51
alpha+19-Mar-02 6:51 
GeneralRe: Creating GDI Controls From Scratch Pin
Tomasz Sowinski19-Mar-02 6:56
Tomasz Sowinski19-Mar-02 6:56 
GeneralRe: Creating GDI Controls From Scratch Pin
Paul M Watt19-Mar-02 7:09
mentorPaul M Watt19-Mar-02 7:09 
GeneralNew and improved solution Pin
Paul M Watt19-Mar-02 9:06
mentorPaul M Watt19-Mar-02 9:06 

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.