简体   繁体   English

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

[英]C++ : no matching function for call to

Sorry for my English. 对不起我的英语不好。

I defined my own function that compare two maps ( if the input includes the word ) . 我定义了自己的比较两个地图的函数(如果输入中包含单词)。 The problem is , when i use it in the anagram function , i have the error " no matching function for call to compare maps " . 问题是,当我在anagram函数中使用它时,出现错误“没有匹配函数来调用比较图”。 I think it's a problem with my arguments , more precisely with iter . 我认为这与我的论点有关,更确切地说与iter有关。 here is my function : 这是我的功能:

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

and in the anagram function (not finished): 并在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());


       }

i think it's a problem with iter->letters.begin() and iter->letters.end() . 我认为iter-> letters.begin()和iter-> letters.end()有问题。 letters is a map in a structure named word . 字母是名为word的结构中的映射。 Dictionary is a vector of word . 字典是单词的向量。 the header is defined like this ( in hpp file ) : 标头是这样定义的(在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);

i'm asking for help ! 我正在寻求帮助! tell me if you want more information 告诉我是否需要更多信息

Assuming Dictionary is defined as: 假设Dictionary定义为:

typedef std::vector<Word> Dictionary;

and Word is defined as: Word定义为:

struct Word
{
    map<char,int> letters;
};

then: 然后:

Dictionary::const_iterator iter

points to const Word , which implies that iter->letters.begin() returns map<char,int>::const_iterator which is not convertible to map<char,int>::iterator required by your function comparemaps . 指向 const Word ,这意味着iter->letters.begin()返回map<char,int>::const_iterator ,它不能转换为功能comparemaps所需的map<char,int>::iterator

Change the signature of your function into: 将函数的签名更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM