C++ : 调用没有匹配函数
C++ : no matching function for call to
对不起我的英语。
我定义了自己的函数来比较两个地图(如果输入包含单词(。问题是,当我在字谜函数中使用它时,我有错误"没有匹配函数来调用比较地图"。我认为这是我的论点的问题,更准确地说是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);
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 返回指向对象的指针的函数调用是否为 prvalue?
- C++ 如何重载 [] 运算符并进行函数调用
- 代码的效率. 转到和函数调用
- 是同一作用域的函数部分中的函数调用
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 类型擦除的std::function与虚拟函数调用的开销