在C / C枚举工作++ [英] Working with enums in C/C++

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

问题描述

我的工作显示这里的code的适应,但是,反而使用个人价值的,我想创建可能值的枚举。

I am working on an adaption of the code shown here, however, instead of using individual values I want to create an enum of possible values.

我想如果可能的话把这个头文件,我想它包含的价值观类似...

I would like to keep this in the header file if possible, and I would like it to include the values something like...

enum Notes{
    NOTE_B0 = 31,
    NOTE_C1 = 33,
    NOTE_CS1 = 35
};

现在我期待通过枚举值进行迭代,我会怎么做呢?

Now I am looking to iterate through the enum values, how would I do this?

也可以我存储值超过255?

Also can I store values over 255?

推荐答案

你能做的最好的是什么地方创建所有的枚举值的静态常量数组,并通过循环。如果枚举值均连续的,你可以通过他们明显迭代很轻松地,但短期的,你的运气了。

The best you can do is create a static const array of all the enum values somewhere and iterate through that. If the enum values were all consecutive you could obviously iterate through them easily enough, but short of that you're out of luck.

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

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