我想问一下return中的">"是什么意思
例如
bool Product::is_better_than(Product b) const
{
if (price == 0) return true;
if (b.price == 0) return false;
return score / price > b.score / b.price;
}
我想问一下return中的">"是什么意思
例如
bool Product::is_better_than(Product b) const
{
if (price == 0) return true;
if (b.price == 0) return false;
return score / price > b.score / b.price;
}
return score / price > b.score / b.price;
在功能上,它与以下内容相同:
if ( score / price > b.score / b.price)
{
return true;
}
else
{
return false;
}
速记表达。也与:
return (score / price > b.score / b.price);
>代表大于。这是一个布尔运算符,它返回:
true如果第一个操作数 ( score / price) 大于第二个操作数 ( b.score / b.price)。false如果第一个操作数小于或等于第二个操作数。因为/优先于>你也可以写。-
return (score / price) > (b.score / b.price);
使您的代码更具可读性。
逻辑语句的结果,例如x > yare bool。所以,
score / price > b.score / b.price
检查左手项是否大于右手项。如果是,则结果为true否则false。
确定结果后,它返回该布尔值。
它与其他任何地方的比较相同,如果score/price大于,函数将返回 true b.score/b.price。
大于的意思。像 5 > 4