Posts

Showing posts with the label Enumerated data types

Enumerated data types in c++

Enumerated data types Simple integer constants are required to represent domain specific data. For example, Colour of an automobile can be specified by a set of statements using cost qualifiers: Const int cRED =0; Const int cBLUE = 1; ……… Int auto_colour; Auto_colour=cBLUE; However, there are no checks. Since variable auto_colour is an integer, the following assignments are valid: auto_colour=-1; …….. auto_colour=rand(); Of course, these statements lose the semantics; variable auto_colour doesn’t any longer represent a colour, it is just an integer. It is thus important to be able to tell the compiler: “Variable auto_colour is supported to represented a colour, that is one of the defined set of choices RED, BLUE,…” and then have the compiler check, pretty thoroughly, that auto_colour is only used in this way throughout the program. This leads to “enumerated data types”. Enumerated data types are an alternative way of declaring a set of inte...