How can I resolve the ambiguous call between these two in C++?
Color(int, int, int)
Color(float, float, float)
It is both ambiguous when the values are hardcoded i.e. Color(1, 2, 3) and when they are variables Color(r, g, b). Why wouldn’t the compiler resolve according to data type? In variable form?
EDIT:
Sorry, too much C++ makes me forget there’s a other languages.
And there is not much “full code” that was all about it.
float x, y, z;
int r, g, b;
Color(1, 2, 3); // ambiguous
Color(1.0, 2.0, 3.0); // ambiguous
Color(r, g, b); // ambiguous <--- this one is a real pain
Color((int)r, (int)g, (int)b); // ambiguous
Color(x, y, z); //OK
Color(1u, 2u, 3u); //OK
Color(1.0f, 2.0f, 3.0f); //OK
The problem seems to be that you have declared
ie, all three args must be either
floatorunsigned. If you try to call it with other types (such asintordouble), its ambiguous — the compiler doesn’t know which you want as both are just a good (or as bad if you prefer). You could improve things a bit by declaring more overloads:but you’d still get ambiguity errors if try to call it with mixed types.