Using an enum as an array index

前端 未结 7 1465
忘了有多久
忘了有多久 2020-12-13 12:30

I have this enum:

enum ButtonState {
    BUTTON_NORMAL = 0,
    BUTTON_PRESSED = 1,
    BUTTON_CLICKED = 2
};

const u8 NUM_BUTTON_STATES = 3;
7条回答
  •  甜味超标
    2020-12-13 12:55

    Question 1: I think it's good programming style. I use it all the time. Question 2: As far as I know, it is guaranteed to work that way, so you don't have to specify the values.

    And I would put NUM_BUTTON_STATES into the enum as well.

提交回复
热议问题