G
gywlily
Unregistered / Unconfirmed
GUEST, unregistred user!
代码一:
BattingAverage a;
BattingAverage b;
...
bool istrue = (a &&
b) ///////////////////////
代码二:
对于上面的////////一句,
编译器在后台将以如下方式合并true,false和&运算符来对&&运算符求值(书中原话)
if (BattingAverage.false(a) != true)
return BattingAverage.true(BattingAverage.Operator&(a, b));
else
return BattingAverage.true(a);
我已经重载了true,false和&运算符,
但是编译提示"无法将类型“HelloWorld.BattingAverage”隐式转换为“bool”"
请问书上为什么这样写?
另外,假设a为非空引用,b为空引用,返回值又将为何值?
重载&运算符:
public static BattingAverage operator &(BattingAverage left, BattingAverage right)
{
if (left.Average() == 0 || right.Average() == 0)
return new BattingAverage();
else
retturn new BattingAverage(..., ...);
}
BattingAverage a;
BattingAverage b;
...
bool istrue = (a &&
b) ///////////////////////
代码二:
对于上面的////////一句,
编译器在后台将以如下方式合并true,false和&运算符来对&&运算符求值(书中原话)
if (BattingAverage.false(a) != true)
return BattingAverage.true(BattingAverage.Operator&(a, b));
else
return BattingAverage.true(a);
我已经重载了true,false和&运算符,
但是编译提示"无法将类型“HelloWorld.BattingAverage”隐式转换为“bool”"
请问书上为什么这样写?
另外,假设a为非空引用,b为空引用,返回值又将为何值?
重载&运算符:
public static BattingAverage operator &(BattingAverage left, BattingAverage right)
{
if (left.Average() == 0 || right.Average() == 0)
return new BattingAverage();
else
retturn new BattingAverage(..., ...);
}