mem_fun_ref
#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都不行啊 你的问题是什么 谢谢,已经解决了,少写了一个头文件#include<functional> 你想问什么?代码运行是正常的。
页:
[1]