标题:定义 C++/CLI枚举
只看楼主
hmsabc
Rank: 2
来 自:贵州省兴义市
等 级:论坛游民
帖 子:97
专家分:19
注 册:2010-8-2
结帖率:100%
 问题点数:0 回复次数:0 
定义 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;
}
搜索更多相关主题的帖子: CLI 定义 枚举 
2010-08-19 22:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-316271-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.075982 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved