Unary Operator Overloading


#include<iostream.h>
#include<constream.h>
class num
 {
     private:
   int a,b,c,d;
     public:
   num(int j, int k, int m, int l)
     {
a=j;
b=k;
c=m;
d=l;
}
   void show(void);
   void operator ++();
   void operator --();
 };
void num::show()
 {
cout<<"A= "<<a<<"B= "<<b<<"C= "<<c<<"D= "<<d;
 }
void num::operator++()
 {
++a;++b;++c;++d;
 }
void num::operator--()
 {
--a;--b;--c;--d;
 }
void main()
 {
clrscr();
num X(3,2,5,7);
cout<<"\n Before increment of X :";
X.show(); 
++X;
cout<<"\n After increment of X :";
X.show();
cout<<"\n Before decrement of X :";
X.show();
--X;
cout<<"\n  After decrement of X :";
X.show(); 
getch();
 } 

No comments:

Related Posts with Thumbnails