OVERLOADING UNARY OPERATORS

OVERLOADING UNARY OPERATORS USING FRIEND FUNCTION


SOURCE CODE

#include “iostream.h”
#include “conio.h”

class unary_opr
{
int num;
public:
unary_opr()
{
num=0;
};
unary_opr(int a)
{
num=a;
}
friend unary_opr operator++(unary_opr);
friend unary_opr operator++(unary_opr,int);
friend unary_opr operator--(unary_opr);
friend unary_opr operator--(unary_opr,int);

void display()
{
cout << "\n The Result Is " << num="++s1.num;" num="s1.num++;" num="--s1.num;" num="s1.num--;" b2="++b1;" b2="b1++;" b3="--b1;" b4="b1--;" size="5">OUTPUT

PREFIX
The Result Is 3
POSTFIX
The Result Is 2
PREFIX
The Result Is 1
POSTFIX
The Result Is 2