双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

find_if function object 问题

快乐田伯光 快乐田伯光 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
struct int_c
{
int i;
char c;

friend ostream & operator<<(ostream & output, int_c ic)
{
return output << ic.i << ", " << ic.c << endl;
}
};
struct func
{
bool operator()(struct int_c a, int b)
{
return (a.i == b);
}
};
bool wwww(struct int_c a, int b)
{
return (a.i == b);
}
int main(int argc, char *argv[])
{
vector<int_c> vecIC;
int_c int_c_node;

for(char c = 'a'; c <= 'z'; c++)
{
int_c_node.i = int(c - 'a');
int_c_node.c = c;
vecIC.push_back(int_c_node);
}
copy(vecIC.begin(), vecIC.end(), ostream_iterator<int_c>(cout));
vector<int_c>::iterator iter;

//iter = find_if(vecIC.begin(), vecIC.end(), bind2nd(func(), 5));
iter = find_if(vecIC.begin(), vecIC.end(), bind2nd(ptr_fun(wwww), 5));
cout << iter->i << ", " << iter->c << endl;
return 0;
}


如上代码,使用红色的为什么编译不过,而使用蓝色的代码正常编译运行。
...全文
评论 14
收藏 已收藏
分享
返回顶部
快乐田伯光
C++ 语言 65,214 成员 250,514 内容