CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 26

Threaded View

  1. #1
    Join Date
    Jan 2006
    Location
    Visby, SWEDEN
    Posts
    78

    Overloading an operator... I'm really not getting it.

    I hope I won't get flamed for this, but after 2 books "Small C++" by Deitel & Deitel, "C++ for java programmers" - Mark Weiss and 2 tutorials on the net, I still don't understand the syntaxes for overloading an operator and how to use them..
    Code:
    ostream &operator<<( ostream &output, const PhoneNumber &number )
    {
       output << "(" << number.areaCode << ") "
    	  << number.exchange << "-" << number.line;
       return output;
    Code:
    Fraction operator+(const Fraction &rhs)
    	{
    		Fraction temp;
    		temp.den = this->den * rhs.den;
    		temp.num = rhs.den * this->num +
    			this->den * rhs.num;
    		return temp;
    	}
    Aha! This says very much to me..
    Code:
       bool operaotr==(const Card& rhs) const
       {
          return suit == rhs.suit && value == rhs.value;
       }
    
    Card aceSpades(Card::spade, 1);
    what's with the &rhs's everywhere? Is aceSpades line supposed to have something to do with the overloading?

    I've looked around some more on the net and all they do is take examples from a physisist's physics calculating class or something and spew code all over and then they say: "See? That wasn't so hard", and I'm like, what the hell happened here? What is what?

    There is no place where they explain step by step how to initiate it and then use it....
    Last edited by dreamfluid; January 29th, 2006 at 07:56 AM.
    "The best ideas aren't better than the worst, if you don't do anything about it."
    So I guess that's why I'm here... Now I just hope it's a good one.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured