有没有办法在 C++ 中找到枚举的最大值和最小值?
Is there a way to find the maximum and minimum defined values of an enum in c++?
不,没有办法在 C++ 中找到任何枚举的最大值和最小值.当需要此类信息时,定义 Last 和 First 值通常是一种很好的做法.例如,
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
};
不需要为 First
和 Last
之间的每个值指定命名值.
There do not need to be named values for every value between First
and Last
.
这篇关于C++ 枚举中的最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!