1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <string>
#include <unordered_map>
using namespace std;
unordered_map<int,Monster> MManifest;
class Monster
{
enum { Key=1 };
public:
Monster(string,short,int,int,int,int,short,short,short,short,long,int) {}
Monster(const Monster& copy) {}
static Monster Summon();
};
Monster Monster::Summon()
{
auto it = MManifest.find( Key ) ;
if ( it == MManifest.end() )
{
auto pair = MManifest.emplace(std::make_pair(Key, Monster("Goblin", 1, 50, 50, 10, 10, 7, 3, 1, 1, 2, 1))) ;
if ( pair.second == true )
return *pair.first ;
else
throw ; // obviously you'll want to do something more here on a failed insertion.
}
else
return it->second ;
}
int main()
{
Monster m = Monster::Summon() ;
}
|