I tried using the enum in a for loop like this:
enum foo { foo_0, foo_1, foo_2, foo_3, ... foo_n, foo_count }; for(foo f = foo_0; f < foo_count; ++f)
and I had a compilation error. I understand that this is not true because ++ f cannot be a valid enum enum - not in this case, but in the general case, so I switched the for loop to this:
for(foo f = foo_0; f < foo_count; f = foo(f+1))
which compiles fine. But that raises the question. What happens if I get a statement?
foo f = foo(k); //k is not a valid foo value
Is this behavior undefined?
EDIT: k is an int and has no corresponding value in foo
EDIT2:
enum foo { foo_0, foo_1, foo_2, foo_3 }; foo f = foo(100);
Thanks for the help!
source share