I am trying to set up my non-member overloaded function for the following example and keep getting the following error from line 23:
error: could not convert '{((& f2)->Fraction::getValNum() * (& f1)->Fraction::getValDenom())}' from '<brace-enclosed initializer list>' to 'Fraction'
return{f2.getValNum() * f1.getValDenom()};
You forgot to specify your return type for the two getters, as wells as the print function.
Also, how will multiplying the numerator of one fraction with the denominator of the other give you the correct answer? Shouldn't you multiply across (num*num and denom*denom) ?
Here's what that would look like:
1 2 3 4
Fraction operator*(Fraction &f2, Fraction &f1)
{
return Fraction(f2.getValNum() * f1.getValNum(), f2.getValDenom() * f1.getValDenom() ); // construct a Fraction object and return it
}
Only thing left is a function to reduce to simplest form. But I'll leave that to you.
Using getters inside a class is slightly inefficient (it causes an unnecessary function call unless the function is inlined), and also makes your code more verbose (harder to read).