Max and min values in a C++ enum

后端 未结 6 971
广开言路
广开言路 2020-12-09 00:34

Is there a way to find the maximum and minimum defined values of an enum in c++?

6条回答
  •  囚心锁ツ
    2020-12-09 01:06

      enum My_enum
        {
           FIRST_VALUE = 0,
    
           MY_VALUE1,
           MY_VALUE2,
           ...
           MY_VALUEN,
    
           LAST_VALUE
        };
    

    after definition, My_enum::LAST_VALUE== N+1

提交回复
热议问题