מה לא singleton בזה?
#ifndef _Factory #define _Factory class Factory; // Forward decleration #include "D20Character.hpp" #include <map> #include <iostream> using namespace std; using D20Rules:
20Character; class Factory { static map<int, D20Character *> mapFactoryList; int iIndex; public: inline Factory(int iRequestedIndex) { iIndex = iRequestedIndex; } ~Factory() { /*for ( int i = 0; i < mapFactoryList.size(); i++ ) delete mapFactoryList;*/ } static int addItem(D20Character *cCharacter) { for ( int i = 0; i < mapFactoryList.size(); i++ ) if ( mapFactoryList == cCharacter ) return -1; int iThisIndex = mapFactoryList.size(); mapFactoryList.insert(make_pair(iThisIndex, cCharacter)); return iThisIndex; } inline D20Character *getInstance() { return mapFactoryList[iIndex]; } }; #endif