C++ 枚举中的最大值和最小值 [英] Max and min values in a C++ enum

查看:20
本文介绍了C++ 枚举中的最大值和最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 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
};

不需要为 FirstLast 之间的每个值指定命名值.

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

这篇关于C++ 枚举中的最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆