如何在 C++ 中解决这两者之间的模棱两可的调用?
Color(int, int, int)
Color(float, float, float)
Color(1, 2, 3)
当值是硬编码时,即当它们是变量时,它都是模棱两可的Color(r, g, b)
。为什么编译器不根据数据类型解析?以可变形式?
编辑:对不起,太多的 C++ 让我忘记了还有其他语言。并且没有太多关于它的“完整代码”。
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