本文介绍了C ++“或”算子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可以通过某种方式完成吗?
can this be done somehow?
if((a || b) == 0) return 1;
return 0;
所以就像...如果a OR b等于零,那么...但是不是为我工作。
我的真实代码是:
so its like...if a OR b equals zero, then...but it is not working for me.my real code is:
bool Circle2::contains(Line2 l) {
if((p1.distanceFrom(l.p1) || p1.distanceFrom(l.p2)) <= r) {
return 1;
}
return 0;
}
推荐答案
您需要写完整的表达式:
You need to write the full expression:
(a==0)||(b==0)
并在第二个代码中:
if((p1.distanceFrom(l.p1)<= r) || (p1.distanceFrom(l.p2)<=r) )
return 1;
如果您这样做(((a || b)== 0)
的意思是 a
和 b
的逻辑或等于0。但这不是
If you do ((a || b) == 0)
this means "Is the logical or of a
and b
equal to 0. And that's not what you want here.
另外,请注意: if(BooleanExpression)返回true;否则返回false
模式可以缩短为 return BooleanExpression;
And as a side note: the if (BooleanExpression)return true; else return false
pattern can be shortened to return BooleanExpression;
这篇关于C ++“或”算子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!