-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmemfunc1.cpp
More file actions
58 lines (47 loc) · 1.01 KB
/
memfunc1.cpp
File metadata and controls
58 lines (47 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
#include <sequtils.h>
using namespace std;
class Person
{
private :
std::string name;
public :
Person(std::string n) : name(n) {
}
const std::string& getName() const {
return name;
}
void print() const {
std::cout << name << std::endl;
}
void printWithPrefix(std::string prefix) const {
std::cout << prefix << name << std::endl;
}
};
ostream& operator<<(ostream& os, const Person& p)
{
os << "name : " << p.getName() << std::endl;
}
int main(int argc, char *argv[])
{
const char *arr[] = {
"Tushar",
"Sagar",
"Prefix1"
};
vector<Person> v1;
for (int i = 0; i < 3; i++)
v1.push_back(Person(arr[i]));
print_seq(v1, "v1 :\n");
for_each(v1.begin(), v1.end(),
mem_fun_ref(&Person::print));
cout << "================================" << endl;
for_each(v1.begin(), v1.end(),
bind2nd(mem_fun_ref(&Person::printWithPrefix),
"person: "));
cout << endl;
return 0;
}