The operator = () function in our program returns a value by creating a temporary rect object and initialising it using the two arguments constructor. The value returned is a copy of the object of which the overloaded = operator is a member. Cop constructor takes one argument,an object of type rect,passed by reference. < /FONT >



Code:
#include< iostream.h>
#include< conio.h>
class rect
{
int area;
float len,width;
public:
rect()
{
}
rect(float ll,float wd)
{
len=ll;
width=wd;
area=ll*wd;
}
//Overloading the = operator
rect operator =(rect &r)
{
cout<<endl<<"Assignment operator invoked";
> area=r.area;
len=r.len;
width=r.width;
return rect(len,width);
}
//copy constructor
rect(rect &r)
{
cout<<endl<<"Copy constructor invoked";
> len=r.len;
width=r.width;
area=r.len*r.width;
}
void display()
{
cout<< endl<<endl<<"Area= "<< area;
>cout<< endl<< endl<<"Length= "<< len;
> cout<< endl<<endl<<"Width= "<< width;
}
};
void main()
{
clrscr();
rect r1(4.5,10);
rect r2;
r2=r1;
//Copy constructor invoked
rect r3=r1;
r1.display();
r2.display();
r3.display();
}