关于 mem_fun_ref 和 bind2nd的疑问

由于是疑问贴,所以直接上代码:<代码中红色部分有疑问>

 1 // StandLibP307.cpp : 定义控制台应用程序的入口点。
2 //
3
4 #include "stdafx.h"
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 #include <functional>
9 #include <algorithm>
10 using namespace std;
11
12
13 class Person {
14
15 private:
16 std::string name;
17
18 public:
19 Person(void) : name("string") { }
20 void print() const { std::cout << name << std::endl; }
21
22 void printWithPrefix( std::string prefix ) const { std::cout << prefix << name << std::endl; }
23 };
24
25
26 void foo( const std::vector<Person>& coll )
27 {
28
29 for_each( coll.begin(), coll.end(), mem_fun_ref(&Person::print) );
30 for_each( coll.begin(), coll.end(), bind2nd(mem_fun_ref(&Person::printWithPrefix),"person: ") );
31 }
32
33
34
35
36 int _tmain(int argc, _TCHAR* argv[])
37 {
38 Person per;
39 vector<Person> vec;
40 vec.push_back(per);
41 foo(vec);
42
43 return 0;
44 }

  对这里为什么是bind2nd有点不解,调用的对象成员函数printWithPrefix只有一个形参,为什么这里要用bind2nd呢?哪位兄台帮忙解释一下~小弟谢过!!

原文地址:https://www.cnblogs.com/ziyoudefeng/p/2430063.html