Anyone know how to overload a += operator in a rational problem?
Ex:
rational r1 = 5/6
rationa r2 = 3/5
r1+=r2
r1 will have a new value 43/30.
any help will be much appreciated.
Anyone know how to overload a += operator in a rational problem?
Ex:
rational r1 = 5/6
rationa r2 = 3/5
r1+=r2
r1 will have a new value 43/30.
any help will be much appreciated.
I'm not familiar with rationals, but you have to think about how they are added normally and then apply that to the overloaded operator. += is usually declared as a member function so the code might look something like this:
If you explain rationals for me (I cant be arsed to search at the moment), I'lll probably be able to help more.Code:rational& rational::operator +=( rational& rvalue ) { //addition code return *this; }
Last edited by endo; 09-03-2002 at 06:29 AM.
Couldn't think of anything interesting, cool or funny - sorry.