Directory Listing | |
---|---|
basic.cpp
|
|
friend.cpp
|
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
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
class thing {
public:
thing(const string& = "", const int & = 0);
bool operator<(const thing &);
bool operator>(const thing &);
bool operator==(const thing &);
bool operator!=(const thing &);
friend thing& operator+=(thing &, const thing &);
friend ostream& operator<<(ostream&, const thing &);
private:
string yes;
int no;
};
thing::thing(const string& s, const int &i) {
yes = s;
no = i;
}
bool thing::operator<(const thing &rhs) {
return yes < rhs.yes;
}
bool thing::operator>(const thing &rhs) {
return yes > rhs.yes;
}
bool thing::operator==(const thing &rhs) {
return yes == rhs.yes;
}
bool thing::operator!=(const thing &rhs) {
return yes != rhs.yes;
}
thing& operator+=(thing &lhs, const thing &rhs) {
lhs.yes += rhs.yes;
return lhs;
}
//Tell ostream it's alright to access thing
ostream& operator<<(ostream& out, const thing &obj) {
out << "{" << obj.yes << ", " << obj.no << "}";
return out;
}
int main() {
thing a1("a"), a2("a");
cout << (a1 < a2) << endl;
cout << (a1 > a2) << endl;
cout << (a1 == a2) << endl;
cout << (a1 != a2) << endl;
thing a3;
a3 += a2;
a3 += a2;
a3 += a2;
a3 += a2;
cout << a3 << endl;
}