Usually when you do e-terate,
enum Foo {
One,
Two,
Three,
Last
};
for ( int fooInt = One; fooInt != Last; fooInt++ )
{
Foo foo = static_cast<Foo>(fooInt);
// ...
}
It's the same way.
But this is not really an etherate
Two = 9
If you set a value separately, you cannot write it.
Therefore, when dealing with enum
, usually use the switch statement as follows, not iterate, and
switch ( foo )
{
case One:
// ..
break;
Case Two: // intentionally fall
case Three:
// ..
break;
case Four:
// ..
break;
default:
assert( ! "Invalid Foo enum value" );
break;
}
If you really want enum
to be literal, the only way is to put the value of enum
in vector
© 2024 OneMinuteCode. All rights reserved.