-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes(operator-overloading-advance).cpp
78 lines (57 loc) · 1.15 KB
/
classes(operator-overloading-advance).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
70
71
72
73
74
75
76
77
78
#include <iostream>
using namespace std;
class Calculation {
private:
int a;
public:
Calculation(int i = 0) {
a = i;
}
int getA() {
return a;
}
void setA(int a) {
this->a = a;
}
~Calculation() {}
Calculation operator + (Calculation obj) {
Calculation temp;
temp.a = a + obj.a;
return temp;
}
Calculation operator * (Calculation obj) {
Calculation temp;
temp.a = a * obj.a;
return temp;
}
Calculation operator / (Calculation obj) {
Calculation temp;
temp.a = a / obj.a;
return temp;
}
void operator++() {
a++;
}
void operator++(int i) {
a++;
i++;
}
void operator ~ () {
display();
}
// int operator + (int a) {
// return this->a + a;
// }
void display() {
cout << endl << "a = " << a;
}
};
int operator+(Calculation obj) {
return obj.getA();
}
int main() {
Calculation meow(4), meow1(2), meow2(4), meow3(4);
Calculation meowN = (meow * meow1) + (meow2 / meow3);
~meowN;
return 0;
}