today my teacher showed me the following example:
CFraction operator*(const CFraction &a, const CFraction &b){ CFraction x; x.setNumerator(a.getNumerator()*b.getNumerator()); x.setDenominator(a.getDenominator()*b.getDenominator()); return x; } // ... void main(){ CFraction b1,b2(3,7),b3(5,8); b2=b1*3; b2=3*b1; } He said that the above code would be working fine, but if you change the method to the following:
CFraction operator*(CFraction&,CFraction&); it wouldn't work. Why is that?
Hope you can explain it to me.
Thanks in advance.