Search This Blog

Saturday, 22 March 2014

overloading = operator in C++


#include<iostream.h>
#include<conio.h>

class OpOver
{
  public :
       int len,bre;
       int area()
       {
         return len*bre;
       }
       void operator =(OpOver &r)
       {
         len=r.len;
         bre=r.bre;
       }
};

void main()
{
  OpOver a,b,c;

  a.len=3,a.bre=6;
  b.len=2,b.bre=2;
  cout<<"\nArea of first obj "<<" and "<<" is "<<a.area();//18
  cout<<"\nArea of first obj "<<" and "<<" is "<<b.area();    //4
  c=a; // c=a;
  cout<<"\n area of 3rd obj is :"<<c.area(); //18
  getch();
}

No comments:

Popular Posts