Original Post
I have been racking my brains for most of the day trying to figure out how to use boost::ptr_map. I looked around for information, but nothing really answered my questions. Can somebody please help? I want to be able to: * Add objects to a ptr_map. * Use std::string as the key. * Acquire the pointer to the object given a key string. I know these are pretty basic things, but I haven't been able to get it to work. Even though I know the key exists, when this function is called it doesn't work. It just returns NULL.
Obj *get_pointer(const char *name)
{
boost::ptr_map<std::string, Obj>::iterator iter;
std::string tmp_name = name;
iter = my_ptr_map.find(tmp_name);
if (iter != my_ptr_map.end())
{
// I'm not sure about the following line
return (Obj*)&iter
}
return NULL;
}