是'枚举颜色:int {红色,绿色,蓝色};'合法吗? [英] Is 'enum Colour : int { red, green, blue };' legal?

查看:114
本文介绍了是'枚举颜色:int {红色,绿色,蓝色};'合法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有点困惑,因为M $ Visual Studio 2005中的帮助声明枚举的

语法为:


enum [tag ] [:type] {enum-list} [声明者];


所以,可以这样写:


enum Protocol_t: unsigned char {ICMP = 1,TCP = 6,UDP = 17};

struct IPHeader {

// ...

Protocol_t Protocol ;

// ...

};


这对我来说听起来像M $特定的扩展,但它'在VS2005的帮助部分Microsoft Extensions to C and C ++中没有列出这样的

。在另一方面,它没有被包括在Schildt的C ++:The Complete Reference中。 (第4版,

2003)。


cul8r

/ J?rn

I''m a bit confused here, since the help in M$ Visual Studio 2005 states the
syntax for enum as:

enum [tag] [: type] {enum-list} [declarator];

So, it would be possible to write:

enum Protocol_t : unsigned char { ICMP = 1, TCP = 6, UDP = 17 };
struct IPHeader {
// ...
Protocol_t Protocol;
// ...
};

It sounds like an M$ specific extension to me, but it''s not listed as such
in VS2005''s help section "Microsoft Extensions to C and C++". On the other
hand, it''s not included in Schildt''s "C++: The Complete Reference" (4th ed,
2003).

cul8r
/J?rn

推荐答案

Visual Studio 2005将enum的

语法声明为:


enum [tag] [:type] { enum-list} [声明者];


所以,可以这样写:


enum Protocol_t:unsigned char {ICMP = 1 ,TCP = 6,UDP = 17};

struct IPHeader {

// ...

Protocol_t协议;

// ...

};


听起来像M
Visual Studio 2005 states the
syntax for enum as:

enum [tag] [: type] {enum-list} [declarator];

So, it would be possible to write:

enum Protocol_t : unsigned char { ICMP = 1, TCP = 6, UDP = 17 };
struct IPHeader {
// ...
Protocol_t Protocol;
// ...
};

It sounds like an M


对我的具体扩展,但在VS2005的帮助部分Microsoft Extensions to C and C ++中没有列出这样的

。在另一方面,它没有被包括在Schildt的C ++:The Complete Reference中。 (第4版,

2003)。


cul8r

/ J?rn
specific extension to me, but it''s not listed as such
in VS2005''s help section "Microsoft Extensions to C and C++". On the other
hand, it''s not included in Schildt''s "C++: The Complete Reference" (4th ed,
2003).

cul8r
/J?rn


Jorn Ronnow写道:
Jorn Ronnow wrote:
我在这里有点困惑,因为M中的帮助
I''m a bit confused here, since the help in M


这篇关于是'枚举颜色:int {红色,绿色,蓝色};'合法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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