Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
C/C++ Languages
enum class
 How to: Specify Underlying Types of...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual C++ Language Reference
How to: Specify Underlying Types of Enums

By default, the underlying type of an enumeration is int. However, you can specify the type to be signed or unsigned forms of int, short, long, __int32, or __int64. You can also use char or bool.

Code

// mcppv2_enum_3.cpp
// compile with: /clr
typedef bool MYBOOL;

public enum class day_bool : MYBOOL {sun = true, mon = false, tue = true, wed = false, thu = true, fri = false, sat = true};
public enum class day_char : char {sun, mon, tue, wed, thu, fri, sat};

int main() {
   // fully qualified names, enumerator not injected into scope
   day_bool a = day_bool::sun, b = day_bool::mon;   

   System::Console::WriteLine(a);
   bool c = (bool)a;
   System::Console::WriteLine(c);
   c = (bool)b;
   System::Console::WriteLine(c);

   day_char d = day_char::sun, e = day_char::mon;
   System::Console::WriteLine(d);
   char f = (char)d;
   System::Console::WriteLine(f);
   f = (char)e;
   System::Console::WriteLine(f);
   e = day_char::tue;
   f = (char)e;
   System::Console::WriteLine(f);
}

Output

True
True
False
sun
0
1
2

Reference

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker