Is it possible to cycle and extract its value for every item in an enum, e.g:
enum {
item 1 = 1,
item 2 = 7,
item 3 = 'B'
} items;
To say, an array. Possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you mean to construct an array with one element for each value of the enum? Such that you would end up with an array
{1, 7, 'B'}?Not possible. An enum is not much more than a bunch of compile-time constants. At runtime, they are effectively just ints. The compiler doesn’t even check to make sure you are putting valid values in your enum variable (you could put the value 5 in there and it wouldn’t mind). So it has no knowledge of what the possible enum values are at runtime.
Of course, if your enum is contiguous (say, you had defined an enum for the values 0, 1, 2 and 3), then you can do this using a for loop.