Hi,
I have been reading through the Stroustrup book 3e (section 4.8) about
enumerations and there is something I just don't understand...
I thought that the idea of an enum was that you could define some type
that had a set number of values defined by you eg
enum days_of_week {mon, tue, wed, thu, fri, sat, sun};
I was under the impression that if you define a variable of type
days_of_week that it could *only* be one of those seven values listed
above. I typed in the code example in section 4.8 and tested it out
and it seems that you can declare a variable of that type and assign
to it any integer that falls within the range of the enum but that
that integer may not equate to one of the values you defined for the
enum.
So, if I understand correctly, the range for the above will be 0:31?
meaning that I could assign any integer from 0-31 to a days_of_week
variable. In which case lets say I assigned say 19, and then did a
switch on the values above, it would drop down the the default case.
So, whats the point of the enum if values are not restricted to the
ones you specify?
Many thanks,
Caroline M.