Click here to Skip to main content
15,916,692 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralProblem with 'struct' in the same file as 'class'. Pin
WREY7-Oct-03 22:30
WREY7-Oct-03 22:30 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
Mike Dimmick7-Oct-03 23:09
Mike Dimmick7-Oct-03 23:09 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
WREY8-Oct-03 10:40
WREY8-Oct-03 10:40 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
Mike Dimmick9-Oct-03 0:24
Mike Dimmick9-Oct-03 0:24 
GeneralFound it !! Pin
WREY9-Oct-03 6:58
WREY9-Oct-03 6:58 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
WREY9-Oct-03 10:46
WREY9-Oct-03 10:46 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
Mike Dimmick9-Oct-03 22:45
Mike Dimmick9-Oct-03 22:45 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
WREY9-Oct-03 23:29
WREY9-Oct-03 23:29 
While you do make a lot of sense about what you're saying, I always thought variables, functions, classes and structures defined in the same file (be it a header or an implementation file) reside in the same file scope, and for variables and functions defined OUTSIDE a structure or a class, were considered to be global (of sort).

It might sound like I am talking apples and oranges here, but the idea of scope delimited by the preprocessor statements "ifndef HDR (etc.)" guarantees that those symbols (i.e. variables, functions, etc.) would only be processed (or seen by the compiler) just ONCE!!

"extern" simply says, "Take my word for it, this variable (etc.) you see here, has been defined elsewhere." Its purpose is not just to prevent redefinition (which even so, is questionable because symbols appearing in different files are doing so in a different namespace and would not necessarily be duplicates), but also to prevent problems relative to timing (i.e. at what point does a variable (etc.) becomes known to the system since the compiler does not guarantee a specific order of introduction).

I am trying to think back to all those times when I have defined variables (etc.) OUTSIDE a class, believing that they were symbols simply being defined at file scope (a sort of global version in a way) but that I was safe because the system was only going to see them ONCE if I were to surround EVERYTHING in the file with the "#ifndef (etc.)" preprocessor statements!!

Unsure | :~

William

Fortes in fide et opere!
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
Mike Dimmick10-Oct-03 0:34
Mike Dimmick10-Oct-03 0:34 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
Anthony_Yio8-Oct-03 1:23
Anthony_Yio8-Oct-03 1:23 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
David Crow8-Oct-03 2:52
David Crow8-Oct-03 2:52 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
Anthony_Yio8-Oct-03 16:48
Anthony_Yio8-Oct-03 16:48 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
WREY8-Oct-03 9:50
WREY8-Oct-03 9:50 
GeneralRe: Problem with 'struct' in the same file as 'class'. Pin
Anthony_Yio8-Oct-03 16:26
Anthony_Yio8-Oct-03 16:26 
Generalstatic libraries & templates Pin
Themis7-Oct-03 22:21
Themis7-Oct-03 22:21 
GeneralRe: static libraries & templates Pin
Anthony_Yio8-Oct-03 1:03
Anthony_Yio8-Oct-03 1:03 
GeneralRe: static libraries & templates Pin
ZoogieZork8-Oct-03 5:18
ZoogieZork8-Oct-03 5:18 
GeneralRe: static libraries & templates Pin
cmk8-Oct-03 9:55
cmk8-Oct-03 9:55 
GeneralSecure wireless pc Pin
aprogrammer20027-Oct-03 21:52
aprogrammer20027-Oct-03 21:52 
GeneralMultiple choice..Creating Splitter windows Pin
DarkestDreams7-Oct-03 21:24
sussDarkestDreams7-Oct-03 21:24 
GeneralRe: Multiple choice..Creating Splitter windows Pin
Anthony_Yio8-Oct-03 1:12
Anthony_Yio8-Oct-03 1:12 
Generalradio/check backcolor Pin
Gabriel.P.G7-Oct-03 19:05
Gabriel.P.G7-Oct-03 19:05 
GeneralRe: radio/check backcolor Pin
Mike Danberg7-Oct-03 20:39
Mike Danberg7-Oct-03 20:39 
GeneralRe: radio/check backcolor Pin
Rickard Andersson207-Oct-03 22:32
Rickard Andersson207-Oct-03 22:32 
GeneralRe: radio/check backcolor Pin
Jonas Larsson7-Oct-03 23:40
Jonas Larsson7-Oct-03 23:40 

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.