PROGRAM FOR UNARY OPERATOR OVERLOADING USING FRIEND FUNCTION
//program for operator overloading of unary op using friend fn
#include<iostream.h>
#include<conio.h>
class c
{
int x,y,z;
public:
void display()
{
cout<<x<<" "<<y<<" "<<z<<endl;
}
void getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
friend void operator -(c &);
};
void operator -(c &r)
{
r.x=-r.x;
r.y=-r.y;
r.z=-r.z;
}
void main()
{
c s;
clrscr();
s.getdata(-10,90,100);
s.display();
-s;
s.display();
getch();
}
#include<iostream.h>
#include<conio.h>
class c
{
int x,y,z;
public:
void display()
{
cout<<x<<" "<<y<<" "<<z<<endl;
}
void getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
friend void operator -(c &);
};
void operator -(c &r)
{
r.x=-r.x;
r.y=-r.y;
r.z=-r.z;
}
void main()
{
c s;
clrscr();
s.getdata(-10,90,100);
s.display();
-s;
s.display();
getch();
}

Comments
Post a Comment