In my project I have a class named globalClass which kepts global variables for each classes and their created instances.
The aim of this globalClass to send all other classes and their created instances the same value for its each variable. If one class's instance change that value, the others(including main.cpp) must see the new value.
Think that,
- I have a int variable named foo and defined as public and a value of 100 at globalClass.h;
class globalClass
{
public:
int foo = 100;
}
- I have a another classes named class2nd,class3rd,class4th
- I have intances of class2nd,class3rd and class4th defined like (in main.cpp)
#include "class2nd.h"
#include "class3rd.h"
#include "class4th.h"
class2nd class2ndA;
class2nd class2ndB;
class2nd class2ndC;
class3rd class3rdA;
class3rd class3rdB;
class3rd class3rdC;
class4th class4thA;
class4th class4thB;
class4th class4thC;
- I can reach the foo of globalClass from any of the other classes like
(eg. class2nd)
#include "globalClass.h"
globalClass glb;
void globalClass::someFunction()
{
glb.foo = 123;
}
- Now I have to see the foo as 123 from all other class but I see it as 100 as defined on globalClass.h. It can only be seen as 123 on class2nd.
What do I have to do to see the foo as unique from all classes and their instances.... ?