Hi!
Have a look at this. It's an operator overload declared inside a class. It calls a function named GCD(...) which returns the greatest common divisor of two numbers. Then calls the class constructor to create a new class. It reduces a fraction down from say 8/12 to 2/3.
Code:
Fraction Fraction::operator!()
{
int gcd = GCD(numerator, denominator);
return Fraction(numerator / gcd, denominator / gcd);
}
Ok, but I was expecting a warning from the compiler about returning a temporary, but it doesn't. I was wondering why the compiler wouldn't generate a warning about returning a temporary here?
Thanks