如何获得枚举数

编程入门 行业动态 更新时间:2024-10-23 14:24:58
本文介绍了如何获得枚举数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何获得枚举数

我有一个枚举

typedef enum{ DEL_TIME_VALUE = -1, DEL_TIMESEC_VALUE = 100, DEL_TIMEMIN_VALUE = 200, DEL_TIMEHOUR_VALUE = 300, DEL_DAY_VALUE = 1000, DEL_COUNT_VALUE = 1000, .... ..... ..... DEL_END =90002 }WORKINGTIME;

我如何获得枚举数。

我在下面尝试循环!

for(int i=DEL_TIME_VALUE; i<=DEL_END; i++) { }

我猜它不是很好!

任何人都可以告诉我如何获得枚举数!在枚举中声明。

can any one tell me how to get enum count! which are declared in enum.

提前致谢!

推荐答案

你不能。

有一种技术可以让你得到枚举数。它看起来像

There is one technique that allows you to get the enum count. It looks like

typedef enum { value_one, value_two, value_three, ... enum_count } my_enum;

现在价值 enum_count 是枚举中的值。但是,此技术仅在枚举全部带有隐式值时才有效,其中 value_one 为 0 , value_two 是 1 ,等等。因此,枚举中的最后一个值总是具有枚举值的计数。在您的情况下,您的枚举常量具有显式值,这些值不是单调递增的。无法从这种类型的枚举中获取计数。即使在你可以得出计数的理论世界中,这也无济于事,因为你无法得出给定枚举常数的值。

Now the value enum_count is the count of values in the enum. However, this technique only works if the enums all carry their implicit value, where value_one is 0, value_two is 1, etc. Because of this, the last value in the enum always has the value of the count of enum values. In your case, your enum constants have explicit values that are not monotonically incrementing. There is no way to derive a count from this type of enum. And even in the theoretical world where you could derive a count, that wouldn't help you because you could not derive the value of a given enum constant.

更多推荐

如何获得枚举数

本文发布于:2023-10-29 08:13:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539178.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!