Use extern keyword to avoid allocating some memory for yours global variables every time you include your header globalvar.h in multiple files. With this keyword you only allocate them once.
// globalvar.h
#ifndef MYGLOBALS
#define MYGLOBALS
extern int variable1;
extern int variable2;
#endif
...
// globalvar.cpp implementation
int variable1= 0;
int variable = 0;
// globalvar.h
#ifndef MYGLOBALS
#define MYGLOBALS
extern int variable1;
extern int variable2;
#endif
...
// globalvar.cpp implementation
int variable1= 0;
int variable = 0;
To copy to clipboard, switch view to plain text mode
Bookmarks