枚举的默认值? [英] default values to enum ?

查看:126
本文介绍了枚举的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那里,


i正在寻找一些方法来为枚举提供默认值,当我创建一个枚举变量时,它会被初始化为INITIALIZED某些默认值

有可能吗?或者我是否必须编写一些函数来将值分配给

并自己调用它们?

hi there,

i was looking for some way to give default values to enum, when ever i m
creating an enum variable it shuld be INITIALIZED to certain default values
is it possible ? or do i have to write some function for assigning values to
them and call them myself ??

推荐答案



" dumboo" < VT *** @ yahoo.com>在消息中写道

news:c1 ************* @ ID-211285.news.uni-berlin.de ...

"dumboo" <vt***@yahoo.com> wrote in message
news:c1*************@ID-211285.news.uni-berlin.de...
在那里,

我正在寻找一些方法来给枚举赋予默认值,当我创建一个枚举变量时,它应该初始化为某些默认值
是否可能?或者我是否必须编写一些函数来为它们分配值并自己调用它们?
hi there,

i was looking for some way to give default values to enum, when ever i m
creating an enum variable it shuld be INITIALIZED to certain default values
is it possible ? or do i have to write some function for assigning values to
them and call them myself ??




枚举值确实有默认值。

考虑枚举颜色{红色,白色,蓝色};

在这种情况下,红色为0,白色为1,蓝色为2.


更多信息 -
http ://www.parashift.com/c++-faq-lit...html#faq-29.18


祝福,

Sharad




Enum values do have defaults.
Consider enum Color {red, white, blue};
In this case red will be 0, white will be 1 and blue will be 2.

For more -
http://www.parashift.com/c++-faq-lit...html#faq-29.18

Best wishes,
Sharad





" Sharad Kala" <无***************** @ yahoo.com>在消息中写道

news:c1 ************* @ ID-221354.news.uni-berlin.de ...

"Sharad Kala" <no*****************@yahoo.com> wrote in message
news:c1*************@ID-221354.news.uni-berlin.de...

dumboo < VT *** @ yahoo.com>在消息中写道
新闻:c1 ************* @ ID-211285.news.uni-berlin.de ...

"dumboo" <vt***@yahoo.com> wrote in message
news:c1*************@ID-211285.news.uni-berlin.de...
你好,

我正在寻找一些方法来给枚举赋予默认值,当
我创建一个枚举变量时,它应该初始化为某些
的默认值是否可能?或者我是否必须编写一些函数来为它们分配
值并自己调用它们?
hi there,

i was looking for some way to give default values to enum, when ever i m creating an enum variable it shuld be INITIALIZED to certain default values is it possible ? or do i have to write some function for assigning values to them and call them myself ??



枚举值确实有默认值。
考虑枚举颜色{红色,白色,蓝色};
在这种情况下,红色将为0,白色将为1,蓝色将为2.



Enum values do have defaults.
Consider enum Color {red, white, blue};
In this case red will be 0, white will be 1 and blue will be 2.




如何建立默认值?


考虑:


#include< iostream>


enum颜色{红色,白色,蓝色};


int main()

{

颜色c;

std: :cout<< default Color = << c<<" \ n" ;;

}


在几个编译器上试试这个。


Jonathan




" Jonathan Turkanis" < TE ****** @ kangaroologic.com>在留言中写道

news:c1 ************* @ ID-216073.news.uni-berlin.de ...

"Jonathan Turkanis" <te******@kangaroologic.com> wrote in message
news:c1*************@ID-216073.news.uni-berlin.de...

Sharad Kala <无***************** @ yahoo.com>在消息中写道
新闻:c1 ************* @ ID-221354.news.uni-berlin.de ...

"Sharad Kala" <no*****************@yahoo.com> wrote in message
news:c1*************@ID-221354.news.uni-berlin.de...

" dumboo" < VT *** @ yahoo.com>在消息中写道
新闻:c1 ************* @ ID-211285.news.uni-berlin.de ...

"dumboo" <vt***@yahoo.com> wrote in message
news:c1*************@ID-211285.news.uni-berlin.de...
你好,

我正在寻找一些方法来给枚举赋予默认值,当我创建一个枚举变量时,它可以被初始化为某些默认值,这是可能的吗?或者我是否必须编写一些函数来为它们赋值并自己调用它们?
hi there,

i was looking for some way to give default values to enum, when ever i m creating an enum variable it shuld be INITIALIZED to certain default values is it possible ? or do i have to write some function for assigning values to them and call them myself ??



枚举值确实有默认值。
考虑枚举颜色{红色,白色,蓝色在这种情况下,红色将为0,白色将为1,蓝色将为2.



Enum values do have defaults.
Consider enum Color {red, white, blue};
In this case red will be 0, white will be 1 and blue will be 2.



这是如何建立默认值的?

考虑:

#include< iostream>

枚举颜色{红色,白色,蓝色};

int main()
{
颜色c;
std :: cout<< default Color = << c<<" \ n" ;;
}



How does this establish defaults?

Consider:

#include <iostream>

enum Color {red, white, blue};

int main()
{
Color c;
std::cout << "default Color = " << c <<" \n";
}



提出错误的问题..我很糟糕。


Took the question wrong..my bad.


这篇关于枚举的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆