enum type problem

Here's some code:

1
2
3
4
for(NomChef nomChefActuel = 1; nomChefActuel <= NOMBRE_DE_CHEF; nomChefActuel++)
        {
(...)
}


In this for loop, NomChef is an enum type, and I want to loop nomChefActuel to all the values of that type, but I get an "invalid conversion from 'int' to 'NomChef' when compiling... do I have to apply some sort if type casting there?

Thanks,
AeonFlux
Last edited on
Even if you did cast, it would not properly enumerate all values - it might enumerate values that are nonexistent.
well, I have nomChefActuel <= NOMBRE_DE_CHEF as my condition to prevent that, also I make nomChefActuel to start at 1 cause I want to skip the first value...

If I did have to cast, do you know what kind I should use?
That check does not prevent the problem I mentioned.
any ideas, anyone? (if not I'm gonna have to nest an if-else structure to associate an 'int' with all the elements of the enum... it's not that though, but I thought there would be an easier way out of it...) :-/
Last edited on
switch-case is the way to go ;)
yeah thanks hehe... I'm gonna go with that

[edit]

I do have a question though.... it says in the tutorial that enum types have numerical values associated with them... how come we can't use that?? Is it my compiler (code::blocks) ? Or is it something I don't understand ? Help please this is annoying I think it should work...

AeonFlux
Last edited on
yeah thanks hehe... I'm gonna go with that

[edit]

I do have a question though.... it says in the tutorial that enum types have numerical values associated with them... how come we can't use that?? Is it my compiler (code::blocks) ? Or is it something I don't understand ? Help please this is annoying I think it should work...

AeonFlux
You can't use that because multiple enum values could have the same integral value associated with them and some integral values may have no enum value associated with them (e.g. gaps). Additionally, in C++11 enums are not always associated with integral values, so you cannot make that assumption.
ok then... thanks for the input... switch-case it is!! :-)

AeonFlux
Topic archived. No new replies allowed.