home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / ENUM.CP$ / ENUM
Encoding:
Text File  |  1991-12-12  |  496 b   |  21 lines

  1. // ENUM.CPP
  2.  
  3. // This is an example program from Chapter 2 of the C++ Tutorial. This
  4. //     program demonstrates an enumerated data type.
  5.  
  6. enum color { red, orange, yellow, green, blue, violet };
  7.  
  8. void main()
  9. {
  10.     color myFavorite, yourFavorite;
  11.     int i;
  12.  
  13.     myFavorite = blue;
  14.     i = myFavorite;          // Legal; i = 4
  15.  
  16. //  yourFavorite = 5;        // Error: cannot convert
  17.                              //     from int to color
  18.     myFavorite = (color)4;   // Legal
  19. }
  20.  
  21.