-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPreIncrementOverloading.cpp
More file actions
59 lines (55 loc) · 881 Bytes
/
Copy pathPreIncrementOverloading.cpp
File metadata and controls
59 lines (55 loc) · 881 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
50
51
52
53
54
55
56
57
/*
* PreIncrementOverloading.cpp
*
* Created on: 22-Jun-2017
* Author: baliyan
*/
#include <iostream>
using namespace std;
class Test{
int i;
public:
Test():i(0){}
Test(int value):i(value){}
Test(const Test &other){
cout << "copy Constructor "<<endl;
i=other.i;
}
Test& operator=(const Test &other){
cout << " Assignemnt Operaor "<<endl;
i=other.i;
return *this;
}
Test& operator++()
{
cout << "PreIncrementOverloading"<<endl;
Test test;
test.i=++i;
return *this;
}
void display()
{
std::cout<<"Value of i ="<<i<<std::endl;
}
};
int main()
{
/*Test obj1,obj2;
obj1.display();
obj2.display();
obj2=++obj1;
obj1.display();
obj2.display();
++obj1;
obj1.display();*/
Test obj1(10);
Test obj2(20);
Test obj3=obj2;
obj1=obj2=obj3;
++obj3;
obj3.display();
obj2.display();
obj1.display();
obj2=++obj3;
obj3.display();
}