I\'v read several posts here about this kind of errors, but I wasn\'t able to solve this one... Has soon I define the operator int and the function f, fails to compile. I teste
You don't seem to have posted the code that actually causes the error. I guess it looks something like
Fraccao a;
Fraccao b = a + 4;
Fraccao c = 4 + a;
The problem is that your class allows implicit conversions both to and from int
; so a + 4
could be either
int(a) + 4
or
a + Fraccao(4)
with no reason to choose one over the other. To resolve the ambiguity, you could either:
explicit
so that only one (or even neither) conversion can be done implicitly.