C++ “OR” operator

后端 未结 9 1497
无人及你
无人及你 2021-01-19 03:37

can this be done somehow?

if((a || b) == 0) return 1;
return 0;

so its like...if a OR b equals zero, then...but it is not working for me.

9条回答
  •  悲哀的现实
    2021-01-19 04:08

    The C++ language specifies that the operands of || ("or") be boolean expressions.

    If p1.distanceFrom(l.p1) is not boolean (that is, if distanceFrom returns int, or double, or some numeric class type), the compiler will attempt to convert it to boolean.

    For built in numeric type, the conversion is: non-zero converts to true, zero converts to false. If the type of p1.distanceFrom(l.p1) is of class type Foo, the compiler will call one (and only one) user defined conversion, e.g., Foo::operator bool(), to convert the expression's value to bool.

提交回复
热议问题