Hello, I am having trouble working with hash_map. I am adding a key-value pair to the map, but when I exit the function it disappears. Here is my code:
SymTabErr SymTabMgr::enter(SymTabEntry* se)
{
SymTab *table;
SymTab st;
SymTabEntry *entry;
size_t x;
mainStack->pop(table);
x = table->count(se->name());
st = *table;
if (x == 0){ //this element doesnt exist yet
st[se->name()] = se; //add se to the hash map
mainStack->push(&st);
return SYMTAB_OK;
}
}
SymTab is a hash_map, which is a collection of SymTabEntry values. The keys are the "names" of the SymTabEntry that is being added. "st[se->name()] = se;" is the line that adding the new data. For the life of this function the data is there, but when I reenter this function the hash_map is empty!
The a pointer to the hash_map is being saved on a global stack.
Thanks for the help.
SymTabErr SymTabMgr::enter(SymTabEntry* se)
{
SymTab *table;
SymTab st;
SymTabEntry *entry;
size_t x;
mainStack->pop(table);
x = table->count(se->name());
st = *table;
if (x == 0){ //this element doesnt exist yet
st[se->name()] = se; //add se to the hash map
mainStack->push(&st);
return SYMTAB_OK;
}
}
SymTab is a hash_map, which is a collection of SymTabEntry values. The keys are the "names" of the SymTabEntry that is being added. "st[se->name()] = se;" is the line that adding the new data. For the life of this function the data is there, but when I reenter this function the hash_map is empty!
The a pointer to the hash_map is being saved on a global stack.
Thanks for the help.