// 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 <iostream>
#include <string>
#include <cstdlib>

using namespace std;

template<class T, int id>
class Singleton
{
   private:
      static Singleton *_instance;
   protected:
      Singleton()
      {
      };
   public:
      static Singleton *Instance()
      {
         if(_instance == NULL)
         {
            _instance = new Singleton();
         }
         return _instance;
      }
      T Data;
};

Singleton<int,1> *Singleton<int,1>::_instance = NULL;
Singleton<int,2> *Singleton<int,2>::_instance = NULL;
Singleton<string,3> *Singleton<string,3>::_instance = NULL;

int main()
{
   Singleton<int,1> *s1 = Singleton<int,1>::Instance();
   s1->Data = 123;
   Singleton<int,2> *s2 = Singleton<int,2>::Instance();
   s2->Data = 456;
   Singleton<string,3> *s3 = Singleton<string,3>::Instance();
   s3->Data = "ABC";
   cout << s1->Data << " " << s2->Data << " " << s3->Data << endl;
   return 0;
}
