employee2.cpp
1.02 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
59
60
61
62
63
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
class Employee
{
string name;
char middle_initial;
long department;
public:
Employee (const string & n, int dept):name (n), department (dept)
{
};
virtual void print () const
{
cout << name << '\t' << department << endl;
}
virtual ~Employee(){};
};
class Manager:public Employee
{
short level;
public:
Manager (const string & name, int dept, int l):Employee (name, dept),
level (l)
{
};
void print () const
{
Employee::print ();
cout << "\tlevel" << level << endl;
}
};
void
print_list (set < Employee * >&s)
{
for (set < Employee * >::const_iterator p = s.begin (); p != s.end (); ++p)
(*p)->print ();
}
void
print_list_2 (set < Employee * >&s)
{
for_each (s.begin (), s.end (), mem_fun (&Employee::print));
}
int
main ()
{
Employee e ("Brown", 1234);
Manager m ("Smith", 1234, 2);
set < Employee * >empl;
empl.insert (&e);
empl.insert (&m);
print_list_2 (empl);
}