Friends
Following program illustrates how to define a class that is guaranteed to have only a single instance:
public: int value; private: singletonBox () : value(0) { } friend theBox(); }; const singletonBox & theBox() { // declare the one and only one box static singletonBox actualBox; // return this singleton object return actualBox;