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

纳布斯

对不起我的英语不好。

我定义了自己的比较两个地图的函数(如果输入中包含单词)。问题是,当我在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);

我正在寻求帮助!告诉我是否需要更多信息

皮特·斯科特尼克(Piotr Skotnicki)

假设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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

发生没有匹配的函数来调用C ++中的错误

C ++-没有匹配的函数来调用'getaddrinfo'

C ++线程-没有匹配的函数来调用

C ++错误::没有匹配的函数来调用'function'

C ++错误:没有匹配的函数来调用'print_size'

C ++没有匹配函数来调用向量push_back

C ++ Boost Geometry错误:没有匹配的函数来调用“ assertion_failed”

C ++错误:没有匹配的函数来调用'simplex615 <arbitraryFunc> :: amoeba

Libtorch C++ - 没有匹配的成员函数来调用 InterpolateFuncOptions 的“size”

list1.erase( hash1.find ( p) ); 没有匹配的函数来调用“擦除”C++

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

C ++错误没有匹配的调用函数

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

C++ - 没有匹配的函数调用

C ++中的可调用类对象:没有匹配的函数来调用'std :: tuple <T> :: tuple(<括号包围的初始化程序列表>)'

c ++:函数“没有匹配的函数可调用”错误

C++ - 在 foreach 中复制向量给出“没有匹配的函数来调用 std::vector<int>::push_back(std::vector<int>&)”

我正在尝试学习如何在c ++中传递指针,但出现错误:没有匹配的函数来调用'test'。我究竟做错了什么?

vscode中的C ++:错误:没有匹配的构造函数来初始化'std :: thread'

在C ++中没有匹配的构造函数来初始化可变参数模板

没有匹配的函数来调用“ getline”

没有匹配的函数来调用sort()

没有匹配的函数来调用

没有匹配的函数来调用“strlen”

在C ++映射中查找值:没有匹配的调用函数

C ++错误没有匹配函数调用静态模板方法

调用 CLASS:CLASSCPP(C++) 没有匹配的函数

C ++ Lambda-错误:没有匹配的函数可调用

TCP-C ++-没有匹配的函数可以调用