"以下方法或属性之间的调用不明确:'fInt.fInt(int,bool)'和'fInt.fInt(long,bool)'"
这是我的两个构造函数:
public fInt(int i, bool scale = true)
{
if (scale) value = i * SCALE;
else value = i;
}
public fInt(long i, bool scale = true)
{
if (scale)
{
if(i > long.MaxValue / SCALE || i < long.MinValue / SCALE)
Debug.LogError("fInt Overflow on creation with scaling");
value = i * SCALE;
}
else value = i;
}
以下是我如何使用隐式转换用int调用一个:
fInt i = 8;
我希望能够同时使用int和long,这样我就可以避免在不需要的情况下进行额外的检查。有什么想法吗?我只需要这样做吗:
fInt i = (int)8;
fInt i2 = (long)9;
如果可以避免的话,我宁愿不需要额外的打字。以下是我的隐式转换:
//implicit int to fInt
public static implicit operator fInt(int i)
{
return new fInt(i);
}
//implicit long to fInt
public static implicit operator fInt(long i)
{
return new fInt(i);
}
这似乎是Unity3D编辑器中的一个错误。。。因为代码在Visual Studio中运行良好。只有当第二个参数是可选的时,它才会混合签名。