C++ : 调用没有匹配函数

C++ : no matching function for call to

本文关键字:函数 调用 C++      更新时间:2023-10-16

对不起我的英语。

我定义了自己的函数来比较两个地图(如果输入包含单词(。问题是,当我在字谜函数中使用它时,我有错误"没有匹配函数来调用比较地图"。我认为这是我的论点的问题,更准确地说是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;
}

在字谜函数中(未完成(:

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()返回不能转换为函数comparemaps所需的map<char,int>::iterator map<char,int>::const_iterator

将函数的签名更改为:

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);