gcc 4.1.2 c99
我在这个ccsmd.h文件中有以下枚举:
enum options_e
{
acm = 0,
anm,
smd,
LAST_ENTRY,
ENTRY_COUNT = LAST_ENTRY
};
enum function_mode_e
{
play = 0,
record,
bridge,
LAST_ENTRY,
ENTRY_COUNT = LAST_ENTRY
};错误消息:
error: redeclaration of enumerator ‘LAST_ENTRY’
error: previous definition of ‘LAST_ENTRY’ was here
error: redeclaration of enumerator ‘ENTRY_COUNT’
error: previous definition of ‘ENTRY_COUNT’ was here我有LAST_ENTRY,所以我可以用它作为数组的索引。所以我喜欢在所有枚举中保持相同。
发布于 2010-04-08 15:40:19
枚举值与定义的枚举存在于同一命名空间中。也就是说,就LAST_ENTRY而言,它类似于(在这里用得很宽松):
enum options_e { /* ... */ );
// for the LAST_ENTRY value in options_e
static const int LAST_ENTRY = /* whatever */;
enum function_mode_e { /* ... */ );
// for the LAST_ENTRY value in function_mode_e
static const int LAST_ENTRY = /* whatever */;正如您所看到的,您正在重新定义LAST_ENTRY,因此出现了错误。最好在枚举值前面加上一些东西来区分它们:
enum options_e
{
options_e_acm = 0,
options_e_anm,
options_e_smd,
options_e_LAST_ENTRY,
options_e_ENTRY_COUNT = options_e_LAST_ENTRY // note this is redundant
};
enum function_mode_e
{
function_mode_e_play = 0,
function_mode_e_record,
function_mode_e_bridge,
function_mode_e_LAST_ENTRY,
function_mode_e_ENTRY_COUNT = function_mode_e_LAST_ENTRY
};尽管现在你失去了你以前想要的东西。(你能澄清一下那是什么吗?)
https://stackoverflow.com/questions/2598240
复制相似问题