Hey people,
found the following in the book I work with:
Code:
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;
}
Why can I set directly to above when it's private?
(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.)