-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass11.cpp
More file actions
49 lines (44 loc) · 927 Bytes
/
Copy pathclass11.cpp
File metadata and controls
49 lines (44 loc) · 927 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
48
49
//overloding of unary operator ++ or --
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class Integer
{
private:
int a;
public:
void setData(int x)
{
a = x;
}
void showdata()
{
cout<<" a = "<<a<<endl;
}
//overloading operator
Integer operator++() //preincreament overloading
{
Integer I;
I.a = ++a;
return I;
}
Integer operator++(int) //'int' this is for compiler to understand difference between post increament and preincreament
{
Integer I;
I.a = a++;
return I;
}
};
int main(int argc, char const *argv[])
{
system("cls");
Integer obj1,obj2;
obj1.setData(18);
obj2 = obj1++; //post increament
obj2.showdata();
obj2 = ++obj1; //obj2 = obj1.oeprator++(); preincreament
obj2.showdata();
system("pause");
return 0;
}