T
Tommo
I am storing some key value pairs in a map as follows:
<code>
bool StaticDataCache:utMarket(uint8_t key,item_t* value)
{
typedef pair<uint8_t,item_t*> entry;
typedef map<uint8_t,item_t*>::iterator iter;
entry newEntry(key,value);
cout << "About to insert with key:" << key << endl;
pair<iter,bool> insertSuccess = marketsMap.insert(newEntry);
return true;
}
</code>
Now suprisingly to me this actually works when i was expecting it not
to. As you may notice the pair , newEntry, is local to this function,
which means, as i understand it, that once this function exits, the
memory used by newEntry is reclaimed and hence the pair inserted into
the map would be invalidated. Can anyone tell me why this is working.
Does the STL pair handle a 'new' behind the scenes??
<code>
bool StaticDataCache:utMarket(uint8_t key,item_t* value)
{
typedef pair<uint8_t,item_t*> entry;
typedef map<uint8_t,item_t*>::iterator iter;
entry newEntry(key,value);
cout << "About to insert with key:" << key << endl;
pair<iter,bool> insertSuccess = marketsMap.insert(newEntry);
return true;
}
</code>
Now suprisingly to me this actually works when i was expecting it not
to. As you may notice the pair , newEntry, is local to this function,
which means, as i understand it, that once this function exits, the
memory used by newEntry is reclaimed and hence the pair inserted into
the map would be invalidated. Can anyone tell me why this is working.
Does the STL pair handle a 'new' behind the scenes??