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

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

问题描述

有没有办法找到c ++中枚举的最大和最小定义值?

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

推荐答案

没有办法找到C ++中任何枚举的最大和最小定义值。当需要这种信息时,定义最后和第一值通常是好的做法。例如,

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
};

不需要为 code>和最后

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

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