Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.92 KB

enums-c-cx.md

File metadata and controls

44 lines (33 loc) · 1.92 KB
title ms.custom ms.date ms.technology ms.reviewer ms.suite ms.tgt_pltfrm ms.topic ms.assetid caps.latest.revision author ms.author manager
Enums (C++/CX) | Microsoft Docs
12/30/2016
cpp-windows
article
99fbbe28-c1cd-43af-9ead-60f90eba6e68
14
ghogen
ghogen
ghogen

Enums (C++/CX)

C++/CX supports the public enum class keyword, which is analagous to a standard C++ scoped enum. When you use an enumerator that's declared by using the public enum class keyword, you must use the enumeration identifier to scope each enumerator value.

Remarks

A public enum class that doesn't have an access specifier, such as public, is treated as a standard C++ scoped enum.

A public enum class or public enum struct declaration can have an underlying type of any integral type although the Windows Runtime itself requires that the type be int32, or uint32 for a flags enum. The following syntax describes the parts of an public enum class or public enum struct.

This example shows how to define a public enum class:

[!code-cppcx_enums#01]

This next example shows how to consume it:

[!code-cppcx_enums#02]

Examples

The next examples show how to declare an enum,

[!code-cppcx_enums#03]

The next example shows how to cast to numeric equivalents, and perform comparisons. Notice that the use of enumerator One is scoped by the Enum1 enumeration identifier, and enumerator First is scoped by Enum2.

[!code-cppcx_enums#04]

See Also

Type System
Visual C++ Language Reference
Namespaces Reference