[solved] access data globally within application
-
Hi,
It's not the role of static variables and global variables are rather frown upon. You should rather consider using a singleton for that kind of things
-
The singleton is part of the software design patterns.
The implementation is easy: make the ctor private and implement one public static function which creates the instance:
class Foo { private: static Foo* _instance; Test(); public: static Foo* getInstance() { if (_instance==NULL) _instance = new Foo(); return _instance; }
cpp:
Foo::_instance = NULL;
And, please, put not all 'global variables' into one place, but consider the SOLID principles ;)