Jan 30, 2013 at 3:08am Jan 30, 2013 at 3:08am UTC
i was wondering how would i return a new item coming from a stl map
at the moment i have this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Declare outside
map<int , Item>ItemDataBase;
Item Item::CreateItem(int ID,Character C)
{
map<int , Item>::iterator iter = ItemDataBase.find(ID);
if (iter != ItemDataBase.end())
{
return iter->second;
}
else
{
cout<<"Item not found" <<endl;
return ;
}
}
i tried this and it didnt work
return new iter->second;
im curious is if there is another way to create a new item that is stored in the map
Last edited on Jan 31, 2013 at 2:38am Jan 31, 2013 at 2:38am UTC
Jan 30, 2013 at 5:12am Jan 30, 2013 at 5:12am UTC
Did you tried ItemDataBase.second;..? i ain't sure about that but may be that work..
Jan 30, 2013 at 6:33am Jan 30, 2013 at 6:33am UTC
@TheIdeasMan
AFAIK std::map only stores std::pairs
@imgregduh
You are searching an empty local map.
Jan 31, 2013 at 2:41am Jan 31, 2013 at 2:41am UTC
the database is delcare on the outside
i have inserted items into the database like this
ItemDatabase[i]= item();
im trying to apply a factory pattern with a map data structure so that when i call somone from the itemdatabase its a new item obj this why i can simply delete it when its used