class Singleton{ static Singleton s; int i; Singleton(int x) : i(x) { } void operator=(Singleton&); Singleton(const Singleton&);public: static Singleton& getHandle() { return s; } int getValue() { return i } void setValue(int x) { i = x }};Singleton Singleton::s(47);int main(){ Singleton& s = Singleton::getHandle(); cout << s.getValue() << endl; Singleton& s2 = Singleton::getHandle(); s2.setValue(9); cout << s.getValue() << endl;}
This example (shamelessly stolen from Bruce Eckel''s Book ''Thinking in C++ 2nd Edition Volume 2) creates a class that can be not be instantiated by the user, the user (read client programmer) can however request a handle from the object. For a better explanation read Bruce Eckels book (follow the link above) it is downloadable in pdf format.
(Testing new sig)
Gyzmo
=======================
Meddle not in the affairs of dragons for you are crunchy and go well with toast.