find_if在C ++中设置:未解析的重载函数类型 [英] find_if in set in C++: unresolved overloaded function type

查看:277
本文介绍了find_if在C ++中设置:未解析的重载函数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用find_if之前的列表和向量在C + +和它的工作正常。但现在,当我尝试使用它与集我得到以下错误:

I have used find_if before with lists and vectors in C++ and it has worked fine. But now, when I try to use it with sets I get the following error:

 error: no matching function for call to ‘find_if(std::set<A, Acmp>::iterator, 
 std::set<A, Acmp>::iterator, <unresolved overloaded function type>)’|

我的课程如下:

bool searchForA(A i) {
   return (i.getVal() > 0);
 }


void B::findA()
 {
   set<A, Acmp> cont;
   set<A, Acmp>::iterator it;
   A *a1 = new A(5);
   A *a2 = new A(7);
   cont.insert(*a1);
   cont.insert(*a2);

   it = find_if (cont.begin(), cont.end(), search)
}

任何人都可以帮助我理解问题在哪里?

Can anyone help me understand where is the problem?

推荐答案

STL调用 search 。这可能是为什么编译器不能解决正确的名称没有更好的提示。您可以重命名您的搜索功能。或者如果你不想这样做,尝试通过 :: search find_if

There's already a function in the STL called search. That's probably why the compiler can't resolve the right name without a better hint. You could rename your search function. Or if you don't want to do that, try passing ::search into find_if instead.

这篇关于find_if在C ++中设置:未解析的重载函数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆