Information Technology Reference
In-Depth Information
Implicit Member Numbering
You can explicitly assign the values for any of the member constants. If you do not initialize a
member constant, the compiler implicitly assigns it a value. The rules the compiler uses for
assigning values to those members are the following:
If the first member does not have an explicit value, the compiler assigns it the value 0 .
￿
￿
For every other member without an initializer, the compiler assigns it the value one
greater than the previous member.
￿
The values associated with the member names do not need to be distinct.
For example, the following code declares two enumerations. CardSuit accepts the implicit
numbering of the members, as shown in the right column. FaceCards sets some members
explicitly and accepts implicit numbering of the others.
enum CardSuit
{
Hearts, // 0--since this is first
Clubs, // 1--one more than the previous one
Diamonds, // 2--one more than the previous one
Spades, // 3--one more than the previous one
MaxSuits // 4--this is a common way to assign a constant
// to the count of the listed items.
}
enum FaceCards
{
// Member // Value assigned
Jack = 11, // 11--explicitly set
Queen, // 12--one more than the previous one
King, // 13--one more than the previous one
Ace, // 14--one more than the previous one
NumberOfFaceCards = 4, // 4--explicitly set
SomeOtherValue, // 5--one more than the previous one
HighestFaceCard = Ace // 14--Ace is defined above
}
Search WWH ::




Custom Search