【发布时间】:2019-11-05 14:36:14
【问题描述】:
我有一种情况,我需要两个枚举来保存一个同名成员。我的代码是 C++,使用 IAR Embeddedj Workbench IDE。代码sn-p如下:
enum Port_e : uint32_t
{
PortA = 0,
PortB,
PortC,
PortD,
PortE,
PortF,
PortG,
PortH,
PortI,
PortJ,
PortK,
NONE
};
enum Pin_e : uint32_t
{
Pin0 = 0, Pin1, Pin2, Pin3, Pin4, Pin5, Pin6, Pin7,
Pin8, Pin9, Pin10, Pin11, Pin12, Pin13, Pin14, Pin15,NONE
};
如果您注意到这里两个枚举的最后一个成员都是 NONE。 此代码无法编译。给出错误,因为 NONE 已经定义。
有什么方法可以在保持名称不变的同时使其构建? 我也不想将类型更改为“枚举类”,因为它会破坏我的应用程序代码的其余部分。
【问题讨论】: