I am trying to get an object inside of a hash_map by reference. It seems simple enough, but I cannot figure out why it doesn't compile. The error is no match for operator=
. In my mind, I am setting the value of fooptr
to the address of the found Foo
object in the map.
void FooManager::GetFoo(Foo *fooptr, std::string name){
std::hash_map<std::string, Foo>::iterator it = this->foos.find(name);
if(it != this->foos.end()){
*fooptr = &it->second;
}
}
Foo *foo = 0;
GetFoo(foo, "test");