例如:
//Does NOT honor the rules of Math precedence
Int32 value=10;
value*=15 + 12; //value=170
//Does honor the rules of Math precedence, and does the multiplication on the second line BEFORE the addition
Int32 value=10;
value=value * 15 + 12; //value=162
我希望第一个能正常工作,编译器会先完成*,但它没有。这是意料之中的,因为 * 在赋值运算符的左侧。有什么方法可以创建另一个像 ++ 和 – 运算符一样运行的运算符,有点像这样......
public Int32 =*(Int32 lhs , Int32 rhs)
{
//Using the above values
lhs=lhs*rhs
}
操作和 =* 将在右侧有 *,因此清楚地指示到达赋值运算符之前的 *。我只是不确定如何在评估 rhs 变量之前将其分解。
任何想法都会有所帮助。
largeQ
慕盖茨4494581
相关分类