I've been making a fraction class recently, I'm not getting the intended results when overloading the operators, and I'm not sure why. Hoping someone can help shed some light. I've tried to only include the relevant code.
const fraction fraction::operator* (fraction frac)
{
return fraction(frac.numerator * numerator, frac.denominator * denominator);
}
const fraction fraction::operator* (int num)
{
return fraction(numerator*num, denominator);
}
fraction& fraction::operator= (const fraction &rightSide)
{
return *this;
}
These operations are the ones I found to be working correctly (where frac# is a fraction object):
frac1 = frac2;
frac3 = frac4 * 2;
frac5 = frac6 * frac7;
The above operations work as expected, but the following operation leaves frac8 just as it was initialized:
fraction frac8(4, 5); // Initializes a fraction, setting numerator = 4, denominator = 5
frac8 = frac8 * 3; // This doesn't quite work, leaving frac8 with the original numerator/denominator
I just don't see quite why frac3 = frac4 * 2 works but frac8 = frac8 * 3 does not. Any ideas? Using the const keyword in the assignment operator I found not to be the solution.