Max and min values in a C++ enum(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
};
不需要为 First
和 Last
之间的每个值指定命名值.
There do not need to be named values for every value between First
and Last
.
这篇关于C++ 枚举中的最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 枚举中的最大值和最小值


- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16