Definition of Enumerator Constants
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Definition of Enumerator Constants

Enumerators are considered defined immediately after their initializers; therefore, they can be used to initialize succeeding enumerators. The following example defines an enumerated type that ensures that any two enumerators can be combined with the OR operator:

// enumerator_constants.cpp
enum FileOpenFlags
   OpenReadOnly  = 1,
   OpenReadWrite = OpenReadOnly  << 1,
   OpenBinary = OpenReadWrite << 1,
   OpenText = OpenBinary    << 1,
   OpenShareable = OpenText      << 1

int main()

In this example, the preceding enumerator initializes each succeeding enumerator.

© 2016 Microsoft