-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathop_over.cpp
More file actions
47 lines (36 loc) · 991 Bytes
/
Copy pathop_over.cpp
File metadata and controls
47 lines (36 loc) · 991 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
//operator overloading , a counter
#include<iostream>
using namespace std;
class count{
public:
count():
ival(0)
{ }
count(int val):
ival(val) { }
~count(){ }
int getval()const {return ival;}
void setval(int x) {ival=x; }
void inc() {++ival; } //increment function
count & operator++(){++ival; //prefix
return *this; } //nameless return this pointer
//making a postfix function
count operator++(int) {count temp(*this); //putting current value of i in temp
++ival; return temp; }
private:
int ival;
};
int main()
{ count i;
cout<<"i is : " <<i.getval();
i.inc() ; cout<<"\n now i is :" <<i.getval() ;
++i;
cout<<"\n after++ i is :" <<i.getval() ;
count a=++i;
cout<<"\n i is : "<<i.getval() <<" a is :"<<a.getval() ;
count b=i++;
cout<<" \n b is :"<<b.getval() <<"\n i is : "<<i.getval() ;
b++;
cout<<"\n after postfix b :" <<b.getval() ;
return 0;
}