-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustom.cpp
More file actions
47 lines (36 loc) · 908 Bytes
/
Custom.cpp
File metadata and controls
47 lines (36 loc) · 908 Bytes
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
#include "stdafx.h"
#include <iostream>
#include <map>
#include <string>
using namespace std;
class Person {
private:
string name;
int age;
public:
Person(): name(""), age(0) {
}
Person(const Person &other) {
cout << "Copy constructor running!" << endl;
name = other.name;
age = other.age;
}
Person(string name, int age): name(name), age(age) {
}
void print() const {
cout << name << ": " << age << endl;
}
};
int _main6(int argc, _TCHAR* argv[]) {
map<int, Person> people;
people[50] = Person("Mike", 40);
people[32] = Person("Raj", 20);
people[1] = Person("Vicky", 30);
people.insert(make_pair(55, Person("Bob", 45)));
people.insert(make_pair(55, Person("Sue", 24)));
for(map<int, Person>::iterator it = people.begin(); it != people.end(); it++) {
cout << it->first << ": " << flush;
it->second.print();
}
return 0;
}