Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 1.64 KB

switch-type.md

File metadata and controls

68 lines (52 loc) · 1.64 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: switch_type
switch_type (C++ COM Attribute)
10/02/2018
vc-attr.switch_type
switch_type attribute
e24544dc-b3bc-48ae-b249-f967db49271e

switch_type

Identifies the type of the variable used as the union discriminant.

Syntax

[switch_type(
type
}]

Parameters

type
The switch type, can be an integer, character, Boolean, or enumeration type.

Remarks

The switch_type C++ attribute has the same functionality as the switch_type MIDL attribute.

C++ attributes do not support encapsulated unions. Nonencapsulated unions are supported only in the following form:

// cpp_attr_ref_switch_type.cpp
// compile with: /LD
#include <windows.h>
[module(name="MyLibrary")];
[ export ]
struct SizedValue2 {
   [switch_type("char"), switch_is(kind)] union {
      [case(1), string]
         wchar_t* wval;
      [default, string]
         char* val;
   };
   char kind;
};

Example

See the case example for a sample use of switch_type.

Requirements

Attribute context Value
Applies to typedef
Repeatable No
Required attributes None
Invalid attributes None

For more information about the attribute contexts, see Attribute Contexts.

See also

IDL Attributes
Typedef, Enum, Union, and Struct Attributes
export