#include<iostream.h>
#include<conio.h>
class unary
{
int t;
public:
void assign(int a){t=a;}
void operator++()
{
cout<<"\n Pre Increment"<<endl;
++t;
}
void operator++(int d)
{
cout<<"\n Post Increment"<<endl;
t++;
}
void operator--(int d)
{
cout<<"\n Post Decrement"<<endl;
t--;
}
void operator--()
{
cout<<"\n Pre Decrement"<<endl;
--t;
}
void show()
{
cout<<t<<endl;
}
};
void main()
{
cout<<"\t\tUnary Operator Overloading Using Member Function";
clrscr();
unary u;
u.assign(10);
++u;
u.show();
u++;
u.show();
--u;
u.show();
u--;
u.show();
getch();
}
Comments
Post a Comment