The switch()… statement revisited
The switch()…
statement is best used when we have a single value that can only have a specified set of values. Doesn't that sound like an enumerated type? It should and, happily, it does.
Using the switch()…
statement to evaluate an enumerated type simplifies the intent of our code and helps to prevent some troublesome situations. Here is the shapeFunc()
function revisited using the switch()…
statement:
enum result_code shapeFunc( enum shape aShape) {
...
switch( aShape )
{
case triangle:
...
break;
case rectangle:
...
break;
case circle:
...
break...