I have a problem in defininig global objects. The linker errors are faced. How to avoid it? Please suggest urgently
Printable View
I have a problem in defininig global objects. The linker errors are faced. How to avoid it? Please suggest urgently
It seems ur objects are not linked with other files.
For global objects u can make extern declarations in one file and u can define and use in other file.
This works for me:
In your main application header file decare your variable as extern.
In the main app implementation file declare and define your variables.
Like this:
[ccode]
//in MyApp.h
extern int global1;
extern char global2;
//etc...Put initial declarations here
//in MyApp.cpp
//declare and define globals here
Josh Knox
Maxym Technologies
This works for me:
In your main application header file decare your variable as extern.
In the main app implementation file declare and define your variables.
Like this:
//in MyApp.h
extern int global1; //extern implies that these variables will be define elsewhere
extern char global2;
//etc...Put initial declarations here
//in MyApp.cpp
//declare and define globals here
int global1 = x;
char global2 = "a";
//these should now be avaiable globally
hope this helps.
Josh Knox
Maxym Technologies