-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice_03.cpp
More file actions
40 lines (39 loc) · 862 Bytes
/
Practice_03.cpp
File metadata and controls
40 lines (39 loc) · 862 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
// Write a program that overloads postfix increment operator to work with user-defined objects.
#include<iostream>
using namespace std;
class Count{
private:
int n;
public:
Count()
{
n = 0;
}
void show()
{
cout<<"n = "<<n<<endl;
}
Count operator ++()
{
Count temp;
n = n+1;
temp.n = n;
return temp;
}
Count operator ++(int) //The keyword int in the following statement indicates that operator is overloaded for postfix. The use of int in Parenthesis is not an integer parameter. It is simple a flog to compiler that indicates that the operator is overloaded for postfix notation.
{
Count temp;
n = n+1;
temp.n = n;
return temp;
}
};
int main()
{
Count x;
x.show();
++x;
x++;
x. show();
return 0;
}