-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunary_Operator_Overloading_With_Native_Function.cpp
More file actions
94 lines (76 loc) · 2.05 KB
/
unary_Operator_Overloading_With_Native_Function.cpp
File metadata and controls
94 lines (76 loc) · 2.05 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
using namespace std;
class Student {
private:
string name;
int age;
public:
Student() {
age = 18;
}
Student(string name, int age) {
this->name = name;
this->age = age;
}
string getName() {
return this->name;
}
void setName(string name) {
this->name = name;
}
int getAge() {
return this->age;
}
void setAge(int age) {
this->age = age;
}
void display() {
cout << "Student Information: " << endl;
cout << "------------------------------------------" << endl;
cout << "Name: " << this->name << endl;
cout << "Age: " << this->age << endl << endl;
}
Student operator++() {
this->age++;
return *this;
}
Student operator++(int notUsed) {
Student temp = *this;
this->age++;
return temp;
}
Student operator--() {
this->age--;
return *this;
}
Student operator--(int notUsed) {
Student temp = *this;
this->age--;
return temp;
}
};
int main() {
Student s1("John", 20);
s1.display();
cout << "Case #7: ++s1 ---> (Student)Y" << endl;
cout << "------------------------------------------" << endl;
Student s2 = ++s1;
s1.display();
s2.display();
cout << "Case #8: s1++ ---> (Student)Y" << endl;
cout << "------------------------------------------" << endl;
Student s3 = s1++;
s1.display();
s3.display();
cout << "Case #9: --s1 ---> (Student)Y" << endl;
cout << "------------------------------------------" << endl;
Student s4 = --s1;
s1.display();
s4.display();
cout << "Case #10: s1-- ---> (Student)Y" << endl;
cout << "------------------------------------------" << endl;
Student s5 = s1--;
s1.display();
s5.display();
return 0;
}