Max and min values in a C++ enum

后端 未结 6 991
广开言路
广开言路 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

    No, there is no way to find the maximum and minimum defined values of any enum in C++. When this kind of information is needed, it is often good practice to define a Last and First value. For example,

    enum MyPretendEnum
    {
       Apples,
       Oranges,
       Pears,
       Bananas,
       First = Apples,
       Last = Bananas
    };
    

    There do not need to be named values for every value between First and Last.

提交回复
热议问题