Greetings,
can anyone give me a sipmle enumerator example and also a simple class example for me to learn and study from. I have checked within here already and it gave me really great info on the basics. Can anyone help me, please?
Printable View
Greetings,
can anyone give me a sipmle enumerator example and also a simple class example for me to learn and study from. I have checked within here already and it gave me really great info on the basics. Can anyone help me, please?
An "interesting" point about "enum's" is that they involve "ranges" of values. You can assign a value to an enum element rather than settling for the default values:
enum color { red = 3, blue = 5, green = 9 };
Wierd part? (Very wierd, actually.):
color orange = color (7); adds 'orange' to the 'enum'. (Don't thank me. Thank Bjarne Stroustrup!) Please note that the rvalue must be preceded by the data "type" (the enum name), or else you messed up!
We need to think "binary" here.
Binary numbers run: 0, 1 , 2, 4, 8, 16, 32, 64, 128...well, you get the point.
When we assign "values" to our enum elements, we effectively set a "range" of values that enum values can fall into. Specifically, our last element is 'green = 9'. Back to our binary example, we must look to the next highest value (binarily speaking) beyond the value given within the enum declaration/definition to see what the "upper" limit is.
Since '9' > '8' - I'm good at this - the next highest binary value is 16. Now, the range for our enum values becomes 1-16, or, in C++ terms, 0- 15.
Therefore, we may assign any additional value to our 'enum' as long as it falls between 0 and 15. Obviously, if our highest original value were 18, for argument's sake, we could go between 0 and 31.
(Probably a lot more than you needed/wanted/cared to know, huh?)
Careful! :D
-Skipper