10.7. Enumerations

Enumeration types are similar to enums in C++. Their definition satisfies the following syntax:


 (4)                 <enum> ::= "enum"
                                <identifier>
                                "{" <enum_body> "}"
 (5)            <enum_body> ::= <enumerator>
                                { "," <enumerator> }*
                                [ "," ]
 (6)           <enumerator> ::= <identifier>
                                "="
                                <int_expr>

Syntax of the integral expression that can be used on the right sight of the enumerator assignemnt is described in Section 10.8.5.2, “Integer Expressions”. Unlike in the C++ enumerations, all IDL enumerants must have assigned a value.

Enumeration type can be defined either in a namespace scope (see Section 10.6, “Namespaces”) or in a class scope (see Section 10.9, “Classes”).

Enumeration types are used in two contexts:

  1. As attribute types. In this case definition of the enumerants and their values is important. See Section 10.8.2, “Attribute Types” for more information.

  2. As property types. In this case only the name of the enumeration type is used in the IDL to C++ mapping. The enumeration should contain no enumerants.

Single enumeration type may be used in both contexts, but it's not recommended to do so.

[Note]Note

So far, the only place where the constants defined in enumerations may be used is an expression in the context of an assignment to an attribute of a relevant enumeration type. Enumeration contants can't be used in integer expressions.