1

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?

Also can I store values over 255?

5
  • 2
    Your file is named 'helloworld.c' and yet you speak of a class. Are you using C++ or C? Commented Apr 17, 2012 at 0:04
  • ...Aaand the error message is gone. Was I hallucinating? Because I don't see an edit log... Commented Apr 17, 2012 at 0:05
  • @RichardJ.RossIII: There's a five minute window after the post is made in which changes can be made without being logged. Commented Apr 17, 2012 at 0:06
  • 2
    @Jackie: Please pick a language. There is no C/C++. Commented Apr 17, 2012 at 0:14
  • @GManNickG I say that because I use C unless I don't understand something (or need OOD), then I use C++. And by C++ I mean the version that comes with GCC Commented Apr 17, 2012 at 12:24

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

they just have to be evenly stepped not consecutive but your point is valid.
Yeah def not in order, just trying to simplify an interface where the user can send a Text representation and it is converted back to the note integer. For example they would pass AS3 and it would itterate till it found the numeric representation on AS3
1

You can store all values which fit in the underlying integer type. With C++11 you can specify the underlying integer. If you don't specify it the compiler will try to find one into which all values fit.

Iteration is not possible, because enum elements are only compile time values. There is no need for the compiler to store them at runtime.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.