首页 新闻 会员 周边

有关函数对象

0
[已解决问题] 解决于 2012-12-04 16:22

 #include <iostream>
#include <algorithm>
using namespace std;

template <class Type>
struct equal_to
{

    bool operator()(Type &a,Type &b)
   {
      return a==b;
   }
};


int main()
{
  int A[]={4,1,0,3,2,0,6};
  const int N=sizeof(A)/sizeof(int);
  int* p=find_if(A,A+N,bind2nd(equal_to<int,int>(),0));
  cout<<p-A<<endl;
  }

想要获得第一个与0相等的数的位置,但编译报错,请高手指教

lzjnhs的主页 lzjnhs | 初学一级 | 园豆:60
提问于:2011-03-21 17:01
< >
分享
最佳答案
1

你这里用了约束器,具体用法看我的博文吧:

[cpp][g.p] STL中的约束器相关总结

奖励园豆:5
zsounder | 老鸟四级 |园豆:2819 | 2012-03-10 03:27
其他回答(1)
0

int* p=find_if(A,A+N,bind2nd(equal_to<int,int>(),0));

里面的bind2nd是什么东东?




Rollen Holt | 园豆:210 (菜鸟二级) | 2012-03-21 16:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册