operator overloading

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2009
Posts: 1
Reputation: adsiq is an unknown quantity at this point 
Solved Threads: 0
adsiq adsiq is offline Offline
Newbie Poster

operator overloading

 
1
  #1
Aug 21st, 2009
how to overload >>,<< operators
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: operator overloading

 
1
  #2
Aug 21st, 2009
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,460
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 189
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso

Re: operator overloading

 
0
  #3
Aug 21st, 2009
usually :

  1. std::ostream& operator <<(std::ostream& ostrm)
  2. {
  3. ostrm << "Hello its overloaded\n";
  4. return ostrm;
  5. }
  6. std::istream& operator >>(std::istream& istrm)
  7. {
  8. cout<<"Enter a number : ";
  9. istrm >> MyClass::myNumber;
  10.  
  11. return istrm;
  12. }

note overloading the << operator should be a friend, so you can use it like this :

cout << myClassVar;

if not then you would use this syntax :

myClassVar <<cout;

which is confusing.
Last edited by firstPerson; Aug 21st, 2009 at 2:59 pm.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle.
2) Problem 2[b]solved by : jonsca
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 3
Reputation: shaneselling is an unknown quantity at this point 
Solved Threads: 0
shaneselling shaneselling is offline Offline
Newbie Poster

Re: operator overloading

 
0
  #4
Sep 21st, 2009
i too have and still have problems with operator overloading, i found the following website helpful. i hope that it does the same for you.


http://www.learncpp.com/cpp-tutorial...tic-operators/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 356 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC