定义 C++/CLI枚举
程序代码:
//定义 C++/CLI枚举 #include "stdafx.h" //#include <iostream> using namespace System; enum class Suit{Clubs,Diamonds,Hearts,Spades}; //全局范围定义牧举 int main(array<System::String ^> ^args) { Suit suit = Suit::Clubs; //定义 suit 为枚举类变量并使之等于 Clubs int value = safe_cast<int>(suit); //将 suit 强制类型转换为 int 并赋给 int 类变量 value Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value); suit = Suit::Diamonds; value = safe_cast<int> (suit); Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value); suit = Suit::Hearts; value = safe_cast<int> (suit); Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value); suit = Suit::Spades; value = safe_cast<int> (suit); Console::WriteLine(L"Suit is {0} and the value is {1}",suit,value); //getchar( ); //system("pause"); return 0; }