-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreAndPost.cpp
More file actions
54 lines (51 loc) · 825 Bytes
/
preAndPost.cpp
File metadata and controls
54 lines (51 loc) · 825 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
/* */
#include <iostream>
using namespace std;
class complex
{
private:
float r = 0, i=0;
public:
complex operator ++ (int n)
{
complex t;
t.r = 10.5;
t.i = 20.5;
cout<<"I am with argument with value: "<<n<<endl;
return t;
}
complex operator ++ ()
{
complex t;
t.r = 10.0;
t.i = 20.0;
cout<<"I am without argument"<<endl;
return t;
}
void reset() { r = 0.0; i = 0.0; }
void display()
{
cout << r <<" "<< i << " " << endl;
}
};
int main()
{
complex c1,c2,c3;
cout << "Without argument increment operator\n";
c1.display();
c2 = ++c1;
c2.display();
c3 = c1.operator ++ ();
c3.display();
c1.reset();
c2.reset();
c3.reset();
cout << "\nWith argument increment operator\n";
c1.display();
c3 = c1++;
c1.display();
c2 = c1.operator ++ (2);
c2.display();
c3.display();
return 0;
}