Two enums have some elements in common, why does this produce an error?

后端 未结 8 677
难免孤独
难免孤独 2021-01-01 09:17

I have two enums in my code:

enum Month {January, February, March, April, May, June, July,
        August, September, October, November, December};
enum Shor         


        
8条回答
  •  孤城傲影
    2021-01-01 09:38

    In C enums are used without any type prefix, so you write:

    month[0] = January;  
    month[4] = May;
    

    The enum Month and ShortMonth have the same scope so the compiler can't know which May to use. An obvious fix would be to prefix the enums but i'm not sure that your use of these enums in this case is warranted.

提交回复
热议问题