Home Segments Index Top Previous Next

609: Mainline

There is a better way to use character codes in switch statements, however. You can change the values of the type-defining enumeration constants. Previously, in Chapter 31, they were declared as follows, with C++ assigning eng_code to 0, box_code to 1, and so on:

enum {eng_code, box_code, tnk_code, cab_code}; 

Recall, however, that you can supply particular integers instead. Further recall that C++ views characters as an integer data type. Thus, you can declare the type-defining enumeration constants as follows:

enum {eng_code = 'E', box_code = 'B', tnk_code = 'T', cab_code = 'C'};