Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cascading operator overloading in c++ 2011
#1
1: in case isf cascading operator overloading what should be return type and expalin its function.

2: in our hand outs no complete example on operator overloading plz write me complete example on + opearator overloadimng so that i can run it on compiler.
Reply
#2
Here is a complete chunk of code that will certainly help you in understanding this important concept.
#include <iostream.h>
class Exforsys
{
private:
int x;
int y;

public:
Exforsys() //Constructor
{ x=0; y=0; }


void getvalue( ) //Member Function for Inputting Values
{
cout << “\n Enter value for x: “;
cin >> x;
cout << “\n Enter value for y: “;
cin>> y;
}


void displayvalue( ) //Member Function for Outputting Values
{
cout <<”value of x is: “ << x <<”; value of y is: “<<y
}


Exforsys operator +(Exforsys);
};


Exforsys Exforsys :: operator + (Exforsys e2)
//Binary operator overloading for + operator defined
{
int x1 = x+ e2.x;
int y1 = y+e2.y;
return Exforsys(x1,y1);
}


void main( )
{
Exforsys e1,e2,e3; //Objects e1, e2, e3 created
cout<<\n”Enter value for Object e1:”;
e1.getvalue( );
cout<<\n”Enter value for Object e2:”;
e2.getvalue( );
e3= e1+ e2; //Binary Overloaded operator used
cout<< “\nValue of e1 is:”<<e1.displayvalue();
cout<< “\nValue of e2 is:”<<e2.displayvalue();
cout<< “\nValue of e3 is:”<<e3.displayvalue();
}

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is Function Overloading in C++ Vuhelper 0 5,399 05-31-2012, 01:45 AM
Last Post: Vuhelper
  explain this operator -> which is use as headnode->stnext(null); Vuhelper 0 1,723 01-04-2012, 10:26 PM
Last Post: Vuhelper
  array project code c++ 2011 Vuhelper 0 1,272 12-10-2011, 06:32 PM
Last Post: Vuhelper
  factorial in C++ code 2011 Vuhelper 0 943 12-10-2011, 06:31 PM
Last Post: Vuhelper
  stack during function call in C++ 2011 Vuhelper 0 2,025 11-05-2011, 05:05 PM
Last Post: Vuhelper
  What is the Thing Queue? in c++ 2011 Vuhelper 0 1,785 11-05-2011, 05:02 PM
Last Post: Vuhelper
  ASCII to char conversion code in C++ 2011 Vuhelper 0 1,720 11-05-2011, 05:01 PM
Last Post: Vuhelper
  How to write a summation in a sequence? C++ 2011-12 Vuhelper 2 1,355 09-19-2011, 04:53 AM
Last Post: Xpert
  GetPixel problem in c++ 2011-12 Vuhelper 0 2,504 09-18-2011, 07:12 PM
Last Post: Vuhelper
  C++ with loop code 2011-12 Vuhelper 0 975 09-18-2011, 07:09 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)