I have a class which should be declared globally from main() and accessed from other declared classes in the program, how do I do that?
class A{
int i;
int value(){ return i;}
};
class B{
global A a; //or extern??
int calc(){
return a.value()+10;
}
}
main(){
global A a;
B b;
cout<<b.calc();
}
You probably really do not want to do this, but if you must – in the file that contains main:
and then in the files that need to access the global:
You will need to put the declaration of A in the A.h header file in order for this to work.