OPERATOR OVER-LOADING

// OPERATOR OVER-LOADING
#include
#include
class unary
{
public:
int x;
int y;
public:
void get_x()
{
cout<<"\n\nEnter a value:"; cin>>x;
}
int dis_y()
{
cout<
return 0;
}
unary operator++();
unary operator++(int a);
unary operator--();
unary operator--(int a);
};
unary unary::operator++()
{
unary temp;
temp.y=++x;
return(temp);
}
unary unary::operator++(int)
{
unary temp;
temp.y=x++;
return(temp);
}
unary unary::operator--()
{
unary temp;
temp.y=--x;
return(temp);
}
unary unary::operator--(int)
{
unary temp;
temp.y=x--;
return(temp);
}
int main()
{
clrscr();
cout<<"\n OUTPUT";
unary c1,c2;
c1.get_x();
cout<
cout<<"\n PRE_INCREMENT:";
c2=++c1;
c2.dis_y();
cout<
c1.get_x();
cout<<"\n POST_INCREMENT:";
c2=c1++;
c2.dis_y();
cout<
c1.get_x();
cout<<"\n PRE_DECREMENT:";
c2=--c1;
c2.dis_y();
cout<
c1.get_x();
cout<<"\n POST_DECREMENT:";
c2=c1--;
c2.dis_y();
cout<
getch();
return 0;
}


Comments