我在一个名为accesrightsByRank
的map
中遇到了从set
中删除元素的问题。该映射的键是不同的ACCESRIGHT
s: owner
, modify
, read
和none
。 map
的值是带有特定ACCESRIGHT
s的访问者名称的set
s。
map<ACCESSRIGHT, set<string>>::const_iterator i;
set<string>::const_iterator j;
for(i = this->accessrightsByRank.begin(); i != this->accessrightsByRank.end(); i++){
for(j = (*i).second.begin(); j != (*i).second.end(); j++){
if( (*j).compare(p_Username) == 0){
i->second.erase(j);
}
}
}
我原以为 i->second
可以给我提供一个 set
,从中可以删除没有特定 ACCESRIGHT
的用户名,但似乎我做错了什么。有人能解释一下为什么这不起作用,以及我应该如何调整我的代码吗?
这是我收到的错误:
IntelliSense: 无法匹配函数重载的实例 "
std::set<_Kty, _Pr, _Alloc>::erase
[with_Kty=std::string
,_Pr=std::less<std::string>
,_Alloc=std::allocator<std::string>
]" 的参数列表和对象(对象具有阻止匹配的类型限定符) 参数类型为:(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::string>>>
) 对象类型为:const std::set<std::string, std::less<std::string>, std::allocator<std::string>>
const_iterator
返回const set<string>&
作为second
。 - Piotr Skotnickimap
和set
的初衷。你应该使用set::find
而不是线性搜索。 - PaulMcKenzieconst_iterator
的教训,然后放弃这段代码并使用multimap。 - Beta