两个枚举有一些共同的元素,为什么会产生这样的错误? [英] Two enums have some elements in common, why does this produce an error?
本文介绍了两个枚举有一些共同的元素,为什么会产生这样的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个枚举在我的code:
I have two enums in my code:
enum Month {January, February, March, April, May, June, July,
August, September, October, November, December};
enum ShortMonth {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
月
在两个枚举一个共同的元素,所以编译器说:
May
is a common element in both enums, so the compiler says:
的枚举的重新说明月
的
为什么会这么说?我怎么能绕过这个?
Why does it say so? And how can I circumvent this?
推荐答案
枚举名字在全球范围内,他们必须是唯一的。请记住,你不需要用enum名限定的枚举符号,你做到这:
Enum names are in global scope, they need to be unique. Remember that you don't need to qualify the enum symbols with the enum name, you do just:
Month xmas = December;
不是
Month xmas = Month.December; /* This is not C. */
由于这个原因,你经常看到有人prefixing用枚举的名字符号名称:
For this reason, you often see people prefixing the symbol names with the enum's name:
enum Month { Month_January, Month_February, /* and so on */ };
这篇关于两个枚举有一些共同的元素,为什么会产生这样的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文