//Overloading an assignment operator
#include<iostream.h>
#include<conio.h>
class sample
{
private:
int x, y;
public:
void getdata ()
{
cout <<"\n enter the value of x and y";
cin>> x>>y;
}
void operator = (sample obj)
{
x= obj.x;
y= obj.y;
}
void display ()
{
cout<<"\n value of x="<<x;
cout<<"\n value of y="<<y;
}
};
void main ()
{
clrscr();
sample obj1, obj2;
obj1.getdata ();
obj1.display ();
obj2=obj1;
obj2.display();
getch ();
}
#include<iostream.h>
#include<conio.h>
class sample
{
private:
int x, y;
public:
void getdata ()
{
cout <<"\n enter the value of x and y";
cin>> x>>y;
}
void operator = (sample obj)
{
x= obj.x;
y= obj.y;
}
void display ()
{
cout<<"\n value of x="<<x;
cout<<"\n value of y="<<y;
}
};
void main ()
{
clrscr();
sample obj1, obj2;
obj1.getdata ();
obj1.display ();
obj2=obj1;
obj2.display();
getch ();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.