枚举列表作为数组索引问题 [英] Enum list as array index problem

查看:102
本文介绍了枚举列表作为数组索引问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下方面并遇到问题。我在数组声明行上出错了。关于数组的东西必须至少有一个元素。提前致谢。 D $ />

#include stuff

....


const enum ENUM_LIST {A = 0,B, C,D,E,ENUM_LIST_MAX};


RWCString MESSAGES [ENUM_LIST_MAX]; < ---------------------


消息[A] =" MESSAGE_A";

留言[b] =" MESSAGE_B";

....

留言{ENUM_LIST_MAX] ="" ;;


unsigned int CODES [ENUM_LIST_MAX]; < -----------------------


CODES [A] = 0x0010;

CODES [b] = 0x000F;

....

CODES [E] = 0x1000;

CODES [ENUM_LIST_MAX] = 0x0000 ;


}

I''m trying the following and having problems. I get errors on the array declaration lines. Something about an array must have at least one element. Thanks in advance. D

#include stuff
....

const enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX};

RWCString MESSAGES[ENUM_LIST_MAX]; <---------------------

MESSAGES[A] = "MESSAGE_A";
MESSAGES[b] = "MESSAGE_B";
....
MESSAGES{ENUM_LIST_MAX] = "";


unsigned int CODES[ENUM_LIST_MAX]; <-----------------------

CODES[A] = 0x0010;
CODES[b] = 0x000F;
....
CODES[E] = 0x1000;
CODES[ENUM_LIST_MAX] = 0x0000;

}

推荐答案

>" dof" <做***** @ comcast.net>在消息中写道

新闻:Xq ****************************** @ comcast.com。 ..
>"dof" <do*****@comcast.net> wrote in message
news:Xq******************************@comcast.com. ..
我正在尝试以下方面并遇到问题。我在数组
声明行中遇到错误。 >关于数组必须至少有一个元素。

提前谢谢。 D

#include stuff


const enum ENUM_LIST {A = 0,B,C,D,E,ENUM_LIST_MAX};


不确定const在那里做什么。

RWCString MESSAGES [ENUM_LIST_MAX]; < ---------------------

MESSAGES [A] =" MESSAGE_A";
MESSAGES [b] = MESSAGE_B;
......
MESSAGES {ENUM_LIST_MAX] ="" ;;


忽略{应该是[,ENUM_LIST_MAX不是有效索引。

数组的大小为ENUM_LIST_MAX,有效索引范围为0到

ENUM_LIST_MAX-1(含)。

unsigned int CODES [ENUM_LIST_MAX] ; < -----------------------

CODES [A] = 0x0010;
CODES [b] = 0x000F ;
......
CODES [E] = 0x1000;
CODES [ENUM_LIST_MAX] = 0x0000;


同样的问题:索引无效。

}
I''m trying the following and having problems. I get errors on the array declaration lines. Something >about an array must have at least one element.
Thanks in advance. D
#include stuff
...

const enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX};
Not sure what that const is doing there.

RWCString MESSAGES[ENUM_LIST_MAX]; <---------------------

MESSAGES[A] = "MESSAGE_A";
MESSAGES[b] = "MESSAGE_B";
...
MESSAGES{ENUM_LIST_MAX] = "";
Ignoring the { which should be a [, ENUM_LIST_MAX is not a valid index. The
array is of size ENUM_LIST_MAX, with valid indexes ranging from 0 to
ENUM_LIST_MAX-1, inclusive.
unsigned int CODES[ENUM_LIST_MAX]; <-----------------------

CODES[A] = 0x0010;
CODES[b] = 0x000F;
...
CODES[E] = 0x1000;
CODES[ENUM_LIST_MAX] = 0x0000;
Same problem here: invalid index.

}




你应该发布完整的代码演示了这个关于

数组必须至少有一个元素的内容。问题。如果你复制并粘贴代码和编译器发出的确切消息,那将是最好的。


-

David Hilsee



You should post complete code that demonstrates this "something about an
array must have at least one element" problem. It would be best if you
copied and pasted the code and the exact message emitted by your compiler.

--
David Hilsee


谢谢大卫。


你对你提到的两条线路是正确的。但是,它们不是导致错误的
。列出的代码代表导致问题的'

代码。不幸的是,我不能完全复制它。


错误信息如图所示。编译器在行

指示说该数组至少需要一个元素。一个特定的

问题将是


我可以声明一个枚举,使用该枚举创建一个单位化数组作为

索引,然后单独设置数组的元素?如果订购问题不是
,我会内联初始化变量。


以下代码在types.h中获取包含在其他课程中'.h / .C

个文件。


#include stuff;


enum ENUM_LIST {A = 0,B,C,D,E,ENUM_LIST_MAX};


RWCString MESSAGES [ENUM_LIST_MAX]; < ---------------------


消息[A] =" MESSAGE_A";

留言[b] =" MESSAGE_B";

....

留言[E] =" MESSAGE_E";

unsigned int CODES [ENUM_LIST_MAX]; < -----------------------


CODES [A] = 0x0010;

CODES [b] = 0x000F;

....

CODES [E] = 0x1000;

}


谢谢,


D

" David Hilsee" <哒************* @ yahoo.com>在留言中写道

news:88 ****************************** @ comcast.com。 ..
Thanks David.

You''re right about the two lines you mentioned. However, they are not
causing the error. The code listed is representative of the code that''s
causing the problem. Unfortunately, I can''t copy it exactly.

The error message is as indicated. The compiler crumps at the lines
indicated saying that the array requires at least one element. A specific
question would be

Can I declare an enum, create an unitialized array using that enum as an
index, and then individually set the elements of the array? If it weren''t
for an ordering issue, I''d initialize the variables inline.

The following code is in types.h and gets included in other class'' .h/.C
files.

#include stuff;

enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX};

RWCString MESSAGES[ENUM_LIST_MAX]; <---------------------

MESSAGES[A] = "MESSAGE_A";
MESSAGES[b] = "MESSAGE_B";
....
MESSAGES[E] = "MESSAGE_E";
unsigned int CODES[ENUM_LIST_MAX]; <-----------------------

CODES[A] = 0x0010;
CODES[b] = 0x000F;
....
CODES[E] = 0x1000;
}

Thanks,

D
"David Hilsee" <da*************@yahoo.com> wrote in message
news:88******************************@comcast.com. ..
" dof" <做***** @ comcast.net>在消息中写道
"dof" <do*****@comcast.net> wrote in message


新闻:Xq ****************************** @ comcast.com。 ..


news:Xq******************************@comcast.com. ..

我正在尝试以下方面并遇到问题。我在数组
I''m trying the following and having problems. I get errors on the array


声明行上出错了。 >关于数组必须至少有一个
元素。
提前致谢。 D


declaration lines. Something >about an array must have at least one
element.
Thanks in advance. D

#include stuff


const enum ENUM_LIST {A = 0,B,C,D,E,ENUM_LIST_MAX};
#include stuff
...

const enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX};



不确定const在那里做什么。



Not sure what that const is doing there.


RWCString MESSAGES [ENUM_LIST_MAX]; < ---------------------

MESSAGES [A] =" MESSAGE_A";
MESSAGES [b] = MESSAGE_B;
...
消息{ENUM_LIST_MAX] ="" ;;

RWCString MESSAGES[ENUM_LIST_MAX]; <---------------------

MESSAGES[A] = "MESSAGE_A";
MESSAGES[b] = "MESSAGE_B";
...
MESSAGES{ENUM_LIST_MAX] = "";



忽略{应该是[,ENUM_LIST_MAX不是]一个有效的索引。

数组的大小为ENUM_LIST_MAX,有效索引范围从0到
ENUM_LIST_MAX-1,包括在内。



Ignoring the { which should be a [, ENUM_LIST_MAX is not a valid index.
The
array is of size ENUM_LIST_MAX, with valid indexes ranging from 0 to
ENUM_LIST_MAX-1, inclusive.

unsigned int CODES [ENUM_LIST_MAX]; < -----------------------

CODES [A] = 0x0010;
CODES [b] = 0x000F ;
......
CODES [E] = 0x1000;
CODES [ENUM_LIST_MAX] = 0x0000;
unsigned int CODES[ENUM_LIST_MAX]; <-----------------------

CODES[A] = 0x0010;
CODES[b] = 0x000F;
...
CODES[E] = 0x1000;
CODES[ENUM_LIST_MAX] = 0x0000;



这里的问题相同:索引无效。



Same problem here: invalid index.


}



你应该发布完整的代码来演示这个关于
数组的东西必须至少有一个元素问题。最好是你复制并粘贴代码和编译器发出的确切消息。

-
David Hilsee



You should post complete code that demonstrates this "something about an
array must have at least one element" problem. It would be best if you
copied and pasted the code and the exact message emitted by your compiler.

--
David Hilsee



谢谢大卫。


你对你提到的两行是正确的。但是,它们不是导致错误的
。列出的代码代表导致问题的'

代码。不幸的是,我不能完全复制它。


错误信息如图所示。编译器在行

指示说该数组至少需要一个元素。一个特定的

问题将是


我可以声明一个枚举,使用该枚举创建一个单位化数组作为

索引,然后单独设置数组的元素?如果订购问题不是
,我会内联初始化变量。


以下代码在types.h中获取包含在其他课程中'.h / .C

个文件。


#include stuff;


enum ENUM_LIST {A = 0,B,C,D,E,ENUM_LIST_MAX};


RWCString MESSAGES [ENUM_LIST_MAX]; < ---------------------


消息[A] =" MESSAGE_A";

留言[b] =" MESSAGE_B";

....

留言[E] =" MESSAGE_E";

unsigned int CODES [ENUM_LIST_MAX]; < -----------------------


CODES [A] = 0x0010;

CODES [b] = 0x000F;

....

CODES [E] = 0x1000;

}


谢谢,


D

" David Hilsee" <哒************* @ yahoo.com>在留言中写道

news:88 ****************************** @ comcast.com。 ..
Thanks David.

You''re right about the two lines you mentioned. However, they are not
causing the error. The code listed is representative of the code that''s
causing the problem. Unfortunately, I can''t copy it exactly.

The error message is as indicated. The compiler crumps at the lines
indicated saying that the array requires at least one element. A specific
question would be

Can I declare an enum, create an unitialized array using that enum as an
index, and then individually set the elements of the array? If it weren''t
for an ordering issue, I''d initialize the variables inline.

The following code is in types.h and gets included in other class'' .h/.C
files.

#include stuff;

enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX};

RWCString MESSAGES[ENUM_LIST_MAX]; <---------------------

MESSAGES[A] = "MESSAGE_A";
MESSAGES[b] = "MESSAGE_B";
....
MESSAGES[E] = "MESSAGE_E";
unsigned int CODES[ENUM_LIST_MAX]; <-----------------------

CODES[A] = 0x0010;
CODES[b] = 0x000F;
....
CODES[E] = 0x1000;
}

Thanks,

D
"David Hilsee" <da*************@yahoo.com> wrote in message
news:88******************************@comcast.com. ..
" dof" <做***** @ comcast.net>在消息中写道
"dof" <do*****@comcast.net> wrote in message


新闻:Xq ****************************** @ comcast.com。 ..


news:Xq******************************@comcast.com. ..

我正在尝试以下方面并遇到问题。我在数组
I''m trying the following and having problems. I get errors on the array


声明行上出错了。 >关于数组必须至少有一个
元素。
提前致谢。 D


declaration lines. Something >about an array must have at least one
element.
Thanks in advance. D

#include stuff


const enum ENUM_LIST {A = 0,B,C,D,E,ENUM_LIST_MAX};
#include stuff
...

const enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX};



不确定const在那里做什么。



Not sure what that const is doing there.


RWCString MESSAGES [ENUM_LIST_MAX]; < ---------------------

MESSAGES [A] =" MESSAGE_A";
MESSAGES [b] = MESSAGE_B;
...
消息{ENUM_LIST_MAX] ="" ;;

RWCString MESSAGES[ENUM_LIST_MAX]; <---------------------

MESSAGES[A] = "MESSAGE_A";
MESSAGES[b] = "MESSAGE_B";
...
MESSAGES{ENUM_LIST_MAX] = "";



忽略{应该是[,ENUM_LIST_MAX不是]一个有效的索引。

数组的大小为ENUM_LIST_MAX,有效索引范围从0到
ENUM_LIST_MAX-1,包括在内。



Ignoring the { which should be a [, ENUM_LIST_MAX is not a valid index.
The
array is of size ENUM_LIST_MAX, with valid indexes ranging from 0 to
ENUM_LIST_MAX-1, inclusive.

unsigned int CODES [ENUM_LIST_MAX]; < -----------------------

CODES [A] = 0x0010;
CODES [b] = 0x000F ;
......
CODES [E] = 0x1000;
CODES [ENUM_LIST_MAX] = 0x0000;
unsigned int CODES[ENUM_LIST_MAX]; <-----------------------

CODES[A] = 0x0010;
CODES[b] = 0x000F;
...
CODES[E] = 0x1000;
CODES[ENUM_LIST_MAX] = 0x0000;



这里的问题相同:索引无效。



Same problem here: invalid index.


}



你应该发布完整的代码来演示这个关于
数组的东西必须至少有一个元素问题。最好是你复制并粘贴代码和编译器发出的确切消息。

-
David Hilsee



You should post complete code that demonstrates this "something about an
array must have at least one element" problem. It would be best if you
copied and pasted the code and the exact message emitted by your compiler.

--
David Hilsee






这篇关于枚举列表作为数组索引问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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