我正在尝试将 2 个变量与我的枚举类型进行比较
I'm trying to compare 2 variables with my enum's type
我创建了一个 Enum wearState,然后将 wearState 作为两个变量的类型。但是,当我尝试使用“||”将它们置于 if 条件下时或'&&',它不起作用。
它说:"error : bad operand types for binary operator '||' "
enum wearState {
WRIST_MOVE,
WRIST_IMMOBILE,
BELT_NECK_MOVE,
BELT_NECK_IMMOBILE,
OTHER_IMMOBILE_STATE;
}
enum chargingState {
YES,
NO,
}
wearState lastState;
wearState currentState;
chargingState lastStateCharging;
chargingState currentStateCharging;
if (((currentState = wearState.BELT_NECK_IMMOBILE) || (currentState = wearState.WRIST_IMMOBILE)) &&
(lastStateCharging = chargingState.NO)) {
/* .... */
}
if (((currentState == wearState.BELT_NECK_IMMOBILE) || (currentState == wearState.WRIST_IMMOBILE)) &&
(lastStateCharging == chargingState.NO))
比较两个变量是否请使用“==”,
= 是赋值运算符。
它只能用于为变量赋值,如
String name="Joe";
要与变量进行比较,我们应该使用比较运算符。
==,<=,>=,!=,<,>
是比较运算符;
我创建了一个 Enum wearState,然后将 wearState 作为两个变量的类型。但是,当我尝试使用“||”将它们置于 if 条件下时或'&&',它不起作用。 它说:"error : bad operand types for binary operator '||' "
enum wearState {
WRIST_MOVE,
WRIST_IMMOBILE,
BELT_NECK_MOVE,
BELT_NECK_IMMOBILE,
OTHER_IMMOBILE_STATE;
}
enum chargingState {
YES,
NO,
}
wearState lastState;
wearState currentState;
chargingState lastStateCharging;
chargingState currentStateCharging;
if (((currentState = wearState.BELT_NECK_IMMOBILE) || (currentState = wearState.WRIST_IMMOBILE)) &&
(lastStateCharging = chargingState.NO)) {
/* .... */
}
if (((currentState == wearState.BELT_NECK_IMMOBILE) || (currentState == wearState.WRIST_IMMOBILE)) &&
(lastStateCharging == chargingState.NO))
比较两个变量是否请使用“==”, = 是赋值运算符。 它只能用于为变量赋值,如
String name="Joe";
要与变量进行比较,我们应该使用比较运算符。 ==,<=,>=,!=,<,> 是比较运算符;