switch_type

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

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

  
[switch_type(  
type  
}]  
  

Parameters

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

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;  
};  

See the case example for a sample use of switch_type.

Attribute Context

Applies totypedef
RepeatableNo
Required attributesNone
Invalid attributesNone

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

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

Show: