Hi,
Lets say I have my table
Class Foo{ GHashTable *table; }
foo::foo(){ table = g_hash_table_new(g_str_hash, g_str_equal); }
I have functions like
Foo::update(Address *addr, MyObj *obj){ g_hash_table_insert(table, (char*)addr->toString().c_str(), obj);
}
and in another function
Foo::dostuff(){
update(addr1, obj1); update(addr2, obj2);
}
Each time I call update, it changes the hash table so that lets say addr1->toString().c_str() gave “helloaddress” first, the second time I call it, where it becomes “byebyeaddress” (addr2….), the items in the hash table change.
It seems like the hash table just copies pointers – is that true? If so, how else can I modify this so I can store the correct key and values, without concern that the keys and values will change outside of modifying the hash table?
Thanks.
-Edward |