|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
class person
{
public:
person(string na, int age)
{
name = na;
nage = age;
}
void show()
{
cout << name.c_str() << " " << nage << endl;
}
private:
string name;
int nage;
};
int main()
{
cout << "mem_fun_ref测试\n";
person p1("tangyong", 22);
person p2("tangyong", 23);
person p3("tangyong", 24);
person p4("tangyong", 25);
person p5("tangyong", 26);
vector<person> v{ p1,p2,p3,p4,p5 };
for_each(v.begin(), v.end(), mem_fun_ref(&person::show));
cout << "mem_fun测试\n";
person* ptr1 = new person("tangyong", 22);
person* ptr2 = new person("tangyong", 23);
person* ptr3 = new person("tangyong", 24);
person* ptr4 = new person("tangyong", 25);
person* ptr5 = new person("tangyong", 26);
vector<person*> vx{ ptr1, ptr2, ptr3, ptr4, ptr5 };
for_each(vx.begin(), vx.end(), mem_fun(&person::show));
for_each(vx.begin(), vx.end(), [](person* ptr) {delete ptr; });
system("pause");
return 0;
}
还有那个bind2nd都不行啊 |
|