Here's an example:
enum COLOR { RED, BLUE, GREEN, WHITE, BLACK };
This statement performs two tasks:
It makes COLOR the name of an enumeration, that is, a new type.
It makes RED a symbolic constatnt with the value 0, BLUE with the value 1 and so forth.
If you write:
enum Color { RED=100, BLUE, GREEN, WHITE, BLACK };
then the BLUE value 101, GREEN value 102 and so forth.
How to use:
Color c = RED;
if(c==RED)
{
}
else if(c==BLUE)
{
}
阅读(1954) | 评论(0) | 转发(0) |