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

后端 未结 8 726
难免孤独
难免孤独 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:29

    In C++11 you can use scoped enumerations to fix this this. This will remove the names from the global scope and scope them to the enum name.

    enum class Identity
    {
           UNKNOWN = 1,
           CHECKED = 2,
           UNCHECKED =3
    };
    
    enum class Status
    {
           UNKNOWN = 0,
           PENDING = 1,
           APPROVED = 2,
           UNAPPROVED =3
    };
    
    int main ()
    {
        Identity::UNKNOWN;
        Status::UNKNOW;
    }
    

    Live Example

提交回复
热议问题