c++中enum 如何使用
枚举类型,顾名思义,“枚”作为量词,作“个”讲,那么枚举,就是一个一个的列举,如果一件事情能够被一个一个的列举,那么它的数量肯定就是有限的,否则是不能被一一列举出来的。
所以枚举类型即为能被列举的常量的一个集合。
实例:
1 typedef enum EnumOfSystemCanID
2 {
3 ID_CAN_FIBER_HB = 0x1B0,
4 ID_CAN_FIBER_CTL = 0x1A0,
5
6 ID_CAN_DIO_HB = 0x2B0,
7 ID_CAN_DOI_SMP_1 = 0x2B1,
8 ID_CAN_DOI_SMP_2 = 0x2B2,
9 ID_CAN_DOI_SMP_3 = 0x2B3,
10 ID_CAN_DOI_SMP_4 = 0x2B4,
11
12 ID_CAN_DIO_OUT_CTL = 0x2A0,
13 ID_CAN_DIO_SMP_CTL = 0x2A1,
14 ID_CAN_DIO_PW_OUT = 0x2A2,
15
16 ID_CAN_PWMPTC_HB = 0x3B0,
17 ID_CAN_PWMPTC_SELRES= 0x3A1,
18 ID_CAN_PWMPTC_PWM = 0x3A2,
19 ID_CAN_PWMPTC_SMPCTL= 0x3A3,
20
21 ID_CAN_SIGGEN1_HB = 0x4B0,
22 ID_CAN_SIGGEN1_CTL = 0x4A1,
23 ID_CAN_SIGGEN1_SYNC = 0x4A2,
24
25 ID_CAN_SIGGEN2_HB = 0x5B0,
26 ID_CAN_SIGGEN2_CTL = 0x5A1,
27 ID_CAN_SIGGEN2_SYNC = 0x5A2,
28
29 }E_BRD_CAN_ID;