Max and min values in a C++ enum

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

    you don't even need them, what I do is just I say for example if you have:

    enum Name{val0,val1,val2};
    

    if you have switch statement and to check if the last value was reached do as the following:

    if(selectedOption>=val0 && selectedOption<=val2){
    
       //code
    }
    

提交回复
热议问题