Hey people,
found the following in the book I work with:
Why can I setCode:class Singleton { private: static Singleton *instanz; Singleton() { } public: static Singleton* getInstanz() { if (instanz == NULL) instanz = new Singleton(); return instanz; } }; Singleton* Singleton::instanz = NULL; int main() { Singleton* obj1 = Singleton::getInstanz(); Singleton* obj2 = Singleton::getInstanz(); cout << " obj1: " << &(*obj1) << endl; cout << " obj2: " << &(*obj2) << endl << endl; return 0; }directly toCode:Singleton::instanzaboveCode:NULLwhen it's private?Code:main()
(May be a stupid question, but I worked through a whole chapter of classes, constructors, members, and now I feel a bit overwhelmed with all the new things.)



7Likes
LinkBack URL
About LinkBacks



I see, that's just the definition. Now I feel clearer about that, thanks a lot. I guess I will have to re-read the whole chapter at least one more time to have it all sink in...
