![]() |
![]() |
![]() |
![]() |
![]() |
|
Although there is nothing wrong with defining integer constants using
const int, most experienced C++ programmers would be more likely
to use an
enumeration statement, as in the following example:
enum {eng_code, box_code, tnk_code, cab_code};
Such a statement declares all the symbols in braces to be enumeration
constants and assigns integer values to those constants. By default, the
value of the first enumeration constant is 0; also by default, the
value of each succeeding enumeration constant is 1 more than the previous
value. Hence, the value of eng_code is 0, that of
box_code is 1, that of tnk_code is 2, and that
of cab_code is 3.