// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <cstdlib>
#include <iostream>

using namespace std;

class Counter
{
   private:
      int n;
      static Counter *instance;
      Counter();
   public:
      static Counter *getInstance();
      void increment();
      int get();
};

Counter *Counter::instance = NULL;

Counter *Counter::getInstance()
{
   if(instance==NULL)
   {
      instance = new Counter();
   }
   return instance;
}

Counter::Counter()
{
   n = 0;
}

void Counter::increment()
{
   n++;
}

int Counter::get()
{
   return n;
}

int main()
{
   Counter::getInstance()->increment();
   Counter::getInstance()->increment();
   Counter::getInstance()->increment();
   cout << Counter::getInstance()->get() << endl;
   return 0;
}
