< previous page page_544 next page >

Page 544
    char    char2;
      .
      .
      .
    cin >> char1 >> char2;
    inPatient = CharToAnimal(char1, char2);
      .
      .
      .
    cin >> char1 >> char2;
    outPatient = CharToAnimal(char1, char2);
      .
      .
      .
}
Named and Anonymous Data Types
The enumeration types we have looked at, Animals and Days, are called named types because their declarations included names for the types. Variables of these new data types are declared separately using the type identifiers Animals and Days.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Named Type A user-defined type whose declaration includes a type identifier that gives a name to the type.
C++ also lets us introduce a new type directly in a variable declaration. Instead of the declarations
enum CoinType {NICKEL, DIME, QUARTER, HALF_DOLLAR};
enum StatusType {OK, OUT_OF_STOCK, BACK_ORDERED};

CoinType   change;
StatusType status;
we could write
enum {NICKEL, DIME, QUARTER, HALF_DOLLAR} change;
enum {OK, OUT_OF_STOCK, BACK_ORDERED} status;
A new type declared in a variable declaration is called an anonymous type because it does not have a namethat is, it does not have a type identifier associated with it.

 
< previous page page_544 next page >