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;Aha! This says very much to me..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; }
what's with the &rhs's everywhere? Is aceSpades line supposed to have something to do with the overloading?Code:bool operaotr==(const Card& rhs) const { return suit == rhs.suit && value == rhs.value; } Card aceSpades(Card::spade, 1);
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....




Reply With Quote