C++ Variables
-
;)I have a main C++ Routine with an include file called MyMainFile.h. Have a number of global variables in the include file that I want to be visible to a subroutine that is called from the main C++ program. However, when I call the subroutine, and include the MyMainFile.h in the subroutine, none of the variable that are declared in the include file, MyMainFile.h, are available. The compiler designates them as undeclared variables?? Any ideas? Sid Kraft
Sid
-
;)I have a main C++ Routine with an include file called MyMainFile.h. Have a number of global variables in the include file that I want to be visible to a subroutine that is called from the main C++ program. However, when I call the subroutine, and include the MyMainFile.h in the subroutine, none of the variable that are declared in the include file, MyMainFile.h, are available. The compiler designates them as undeclared variables?? Any ideas? Sid Kraft
Sid
In the include file use the
extern
keyword before usual variable declaration, for instance.extern int myGlobalInteger;
BTW: use sparingly global variables. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.