Click here to Skip to main content
15,894,017 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: using extern in C Pin
Sakhalean23-Jan-12 23:32
Sakhalean23-Jan-12 23:32 
GeneralRe: using extern in C Pin
Jochen Arndt23-Jan-12 23:41
professionalJochen Arndt23-Jan-12 23:41 
AnswerRe: using extern in C Pin
Erudite_Eric24-Jan-12 5:33
Erudite_Eric24-Jan-12 5:33 
AnswerRe: using extern in C Pin
Stefan_Lang24-Jan-12 5:50
Stefan_Lang24-Jan-12 5:50 
GeneralRe: using extern in C Pin
Erudite_Eric24-Jan-12 6:23
Erudite_Eric24-Jan-12 6:23 
GeneralRe: using extern in C Pin
Stefan_Lang24-Jan-12 22:44
Stefan_Lang24-Jan-12 22:44 
GeneralRe: using extern in C Pin
Erudite_Eric25-Jan-12 0:32
Erudite_Eric25-Jan-12 0:32 
AnswerRe: using extern in C Pin
«_Superman_»24-Jan-12 15:37
professional«_Superman_»24-Jan-12 15:37 
I assume what you're trying to do is to create a global variable in Main.cpp and make it read only in other .cpp files?
If so, here is what you can do.

Create the global variable as static in Main.cpp - static int x = 0;
Now create a function in Main.cpp that returns this value - int GetX() { return x; }
Now you can call this function from other .cpp files to get the value of x and also x can only be modified from Main.cpp.

Here you do not need to use the extern keyword at all.
Also to call GetX in other .cpp files, you will need to declare it there - int GetX();
«_Superman 
I love work. It gives me something to do between weekends.


Microsoft MVP (Visual C++)

Polymorphism in C

JokeRe: using extern in C Pin
Peter_in_278024-Jan-12 15:58
professionalPeter_in_278024-Jan-12 15:58 
GeneralRe: using extern in C Pin
Mohibur Rashid24-Jan-12 22:46
professionalMohibur Rashid24-Jan-12 22:46 
QuestionPlaying .wav file Pin
D.Manivelan23-Jan-12 19:33
D.Manivelan23-Jan-12 19:33 
AnswerRe: Playing .wav file Pin
PJ Arends23-Jan-12 19:49
professionalPJ Arends23-Jan-12 19:49 
GeneralRe: Playing .wav file Pin
D.Manivelan23-Jan-12 20:11
D.Manivelan23-Jan-12 20:11 
QuestionCustom drawn button inside the onInitDialog Pin
sdancer7523-Jan-12 8:47
sdancer7523-Jan-12 8:47 
AnswerRe: Custom drawn button inside the onInitDialog Pin
Albert Holguin23-Jan-12 9:20
professionalAlbert Holguin23-Jan-12 9:20 
GeneralRe: Custom drawn button inside the onInitDialog Pin
sdancer7523-Jan-12 20:55
sdancer7523-Jan-12 20:55 
AnswerRe: Custom drawn button inside the onInitDialog Pin
Albert Holguin24-Jan-12 5:09
professionalAlbert Holguin24-Jan-12 5:09 
GeneralRe: Custom drawn button inside the onInitDialog Pin
sdancer7524-Jan-12 21:34
sdancer7524-Jan-12 21:34 
QuestionCScrollView Pin
Bart23-Jan-12 7:21
Bart23-Jan-12 7:21 
AnswerRe: CScrollView Pin
Albert Holguin23-Jan-12 12:12
professionalAlbert Holguin23-Jan-12 12:12 
QuestionDisable OnFileOpen and OnFileSave in SDI Pin
_Flaviu23-Jan-12 5:15
_Flaviu23-Jan-12 5:15 
AnswerRe: Disable OnFileOpen and OnFileSave in SDI Pin
Jochen Arndt23-Jan-12 5:58
professionalJochen Arndt23-Jan-12 5:58 
AnswerRe: Disable OnFileOpen and OnFileSave in SDI Pin
Richard MacCutchan23-Jan-12 6:45
mveRichard MacCutchan23-Jan-12 6:45 
QuestionHow to show transparent image (a .png or .gif file ) in MFC Pin
Amrit Agr23-Jan-12 3:12
Amrit Agr23-Jan-12 3:12 
AnswerRe: How to show transparent image (a .png or .gif file ) in MFC Pin
Eugen Podsypalnikov23-Jan-12 5:01
Eugen Podsypalnikov23-Jan-12 5:01 

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.