【发布时间】:2019-08-02 00:17:03
【问题描述】:
我试图通过引用在 hash_map 中获取一个对象。看起来很简单,但我不知道为什么它不能编译。错误是no match for operator=。在我看来,我将fooptr 的值设置为在地图中找到的Foo 对象的地址。
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");
【问题讨论】:
-
如果
fooptr是Foo *类型,问问自己*fooptr有什么类型。 -
没有
std::hash_map。 -
@Brian 对我来说很好。
-
@peer_2_peer_2 你用什么标准库?
-
好像std::hash_map 确实存在。
标签: c++