OPERATOR OVERLOADING USING UNARY MEMBER FUNCTION
//program for operator overloading of unary op using mem 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;
}
void operator -();
};
void c::operator -()
{
x=-x;
y=-y;
z=-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;
}
void operator -();
};
void c::operator -()
{
x=-x;
y=-y;
z=-z;
}
void main()
{
c s;
clrscr();
s.getdata(-10,90,100);
s.display();
-s;
s.display();
getch();
}

Comments
Post a Comment