inline Fract operator+(const Fract& f1,const Fract& f2){
Fract rez;
return rez.add(f1,f2);
}
//...
Fract Fract::add(const Fract& f1,const Fract& f2) {
int lcmb=gcf_or_lcm(f1.den,f2.den,2);
int mult1=lcmb/f1.den;
int mult2=lcmb/f2.den;
return (f1.num*mult1+f2.num*mult2,lcmb); //and here
}
The "num" and "den" variables are of type int.You can see the difference at line 11
I mention that the class "Fract" has got a constructor that takes two ints.
But anyway,the result is different,where is the problem ?
Interesting, I didn't know you could use the comma operator like that. I definitely don't recommend doing it the second way as I'm sure a lot of people are going to read that and not have a clue what you just did. The first way at least makes sense as to what you're going after.
Anyways, how are they different?
EDIT:
jlb wrote:
First you can only return one item from a function, not two.
It may be legal but it is still only returning one item, and I guarantee it is not what the OP is trying to accomplish.
When you return an item from a function it must be the same type of variable as in the function signature. In this case a Fract. Do you see this return statement returning a Frac?
The function returns a Fract object. I think you're missing the implicit word I keep using. ie, you're not going to see it in the code. The compiler does it in the background.
EDIT:
After further reading, I believe I am wrong here. Although it would be interesting behavior.
ok...so simplifying my code i realized that actually the one int constructor is called there...i was sure that Frameworks respond on this topic was corect http://www.cplusplus.com/forum/beginner/94383/ ... he does exactly what i tried to do but now i realize that there are some mistakes.