...
My post directly answers, in detail, those very questions. |
Oh?
This is how it should look (your code!):
ostream& operator << ( ostream& outs, const Fraction& frac ) |
And mine looks exactly like that. Yes, I didn't add a check for negatives, but I'm just trying to learn about overloading operators. I assume I only work with positives. I compiled, I did get an error. I closed VC++, compiled again without changing the code, and it compiled fine. Now, where did you explain this in detail?
Stop grubbing about for quick answers and start thinking about what it is you are doing. Computer programming requires you to think.
For example, your compiler is complaining about the line Fraction frac3 = frac1 + frac2;.
Whenever you see Foo1 + Foo2, you should also be able to find what it means to use + on a Foo. If you don't tell the computer, how is it to know? (It is too stupid to figure it out on its own.) |
Now, where did I tell you that I didn't write code on how it should use +? I actually did and my code works fine, as mentioned in my post above. There is/was just something wrong with my constructor.
So, what does it mean to add two fractions?
Figure it out and write an overloaded + operator to tell the computer how to add two fractions. Here's some help: |
I'm not stupid. I did write that code.
(Remember that that operator should be a friend of your Fraction class.) |
I've learned it just just be a method of the class, not a friend. Is there any reason it should be a friend and not a normal method?
If you insist on using float for your numerator and denominator fields (which I have already dis-recommended to you), you will not be able to find the GCD. You will instead have to use some simple algebra on the source fractions to get a common denominator... |
Good, I'll make integers of them. And again, this is not about the fractions. I'm just trying to understand operator overloading.
Now, unless you can put some real effort into this I will not answer further. (I've already given you an significant amount of help.) |
I DID put some real effort into this. You just jump to some strange conclusions like I didn't write code to overload the + operator.
Thank you.
@Jsmith: Thanks, I'll have a look at it =)
EDIT:
Thank you Jsmith, that indeed solved all the errors. I'll test all my code this afternoon.