I'm taking a class right now that requires that I know C++, but unfortunately the only programming language I've used is a little bit of C. For my first homework assignment I have to write a data type for rational numbers. Well, I have to override the += operator to add two rational numbers, like so:
rational1 += rational2;
Because you override += operator as a member function, your only parameter is a const pointer to rational2. The thing is, I need to pass both rational 1 and rational2 to a non-member function to get the denominators equal before they can be added. I'm not really sure how to pass rational1 due to the way I'm accessing it. Unfortunately everything I've turned up in my text book and Google consider this too elementary to bear mention. This is what i have so far:
Any help would be greatly appreciated!
rational1 += rational2;
Because you override += operator as a member function, your only parameter is a const pointer to rational2. The thing is, I need to pass both rational 1 and rational2 to a non-member function to get the denominators equal before they can be added. I'm not really sure how to pass rational1 due to the way I'm accessing it. Unfortunately everything I've turned up in my text book and Google consider this too elementary to bear mention. This is what i have so far:
Code:
void rational::operator +=(const rational& second_rational){ equalizeDenominator(rational, second_rational); numerator = numerator + second_rational.numerator; }
Any help would be greatly appreciated!