对不起我的英语不好。
我定义了自己的比较两个地图的函数(如果输入中包含单词)。问题是,当我在anagram函数中使用它时,出现错误“没有匹配函数来调用比较图”。我认为这与我的论点有关,更确切地说与iter有关。这是我的功能:
bool comparemaps(std::map<char, int>::iterator wordfirst , std::map<char, int>::iterator wordlast , std::map<char, int>::iterator inputfirst , std::map<char, int>::iterator inputlast){
map<char, int>::const_iterator w = wordfirst , i=inputlast;
while(w != wordlast){
if(i == inputlast || w->first < i->first)
return false;
if(w->first == i->first){
if(w->second > i->second)
return false;
else
w++;
i++;
}
if(w->first > i->first)
i++;
}
return true;
}
并在anagram函数中(未完成):
vector<vector<string> > anagrams(const string& input , const Dictionary& dict ,
int max){
map<char,int> inputmap;
fillmap(inputmap, input.begin(),input.end());
for( Dictionary::const_iterator iter = dict.begin(); iter != dict.end() ; iter++){
comparemaps(iter->letters.begin(),iter->letters.end(), inputmap.begin(), inputmap.end());
}
我认为iter-> letters.begin()和iter-> letters.end()有问题。字母是名为word的结构中的映射。字典是单词的向量。标头是这样定义的(在hpp文件中):
bool comparemaps(std::map<char, int>::iterator wordbegin , std::map<char, int>::iterator wordlast , std::map<char, int>::iterator inputbegin , std::map<char, int>::iterator inputlast);
我正在寻求帮助!告诉我是否需要更多信息
假设Dictionary
定义为:
typedef std::vector<Word> Dictionary;
和Word
被定义为:
struct Word
{
map<char,int> letters;
};
然后:
Dictionary::const_iterator iter
点来const Word
,这意味着iter->letters.begin()
返回map<char,int>::const_iterator
到这是不可自由兑换的map<char,int>::iterator
要求,你的函数comparemaps
。
将函数的签名更改为:
bool comparemaps(std::map<char, int>::const_iterator wordfirst
, std::map<char, int>::const_iterator wordlast
, std::map<char, int>::iterator inputfirst
, std::map<char, int>::iterator inputlast);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句