Variable Visibility
Hi all,
in msvc++6, cant i put a variable in a header,
or in the header''s cpp, so that i can see it in the main file?
i cant seem to do this?
does anyone remember when they were learning c++, going
thru this error?
Thanx all,
Hugo Ferreira
UniteK Future
"My Name Is Jerry."[TheSphere]
If I understand what you''re asking, you should use the ''extern'' keyword to tell the compiler that a variable exists, but is defined elsewhere (i.e. in another c/cpp file than the one containing the extern-clause).
Also, remember to never define your variables in header files since that may lead to linker errors and stuff (declaring it extern in a header is ok, as long as it is only *defined* in a single c/cpp file).
Also, remember to never define your variables in header files since that may lead to linker errors and stuff (declaring it extern in a header is ok, as long as it is only *defined* in a single c/cpp file).
You should never define a variable in a header file. If you do, and that header file is included in 2 files, then you''ll get a linker error. It''s bad practice. You can put extern''s in headers, but that too is sometimes quesitonable.
My Gamedev Journal: 2D Game Making, the Easy Way
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement