此问题与GCC says "syntax error before numeric constant" in generated header file from bison和I'm getting an error concerning enum (I think)有关,但这里的答案仅给出了为什么人们可能会看到错误“error:syntax error before numeric constant”的错误原因。除非我掩饰它,否则我没有看到任何好的解决方案来避免这个问题(当然除了简单地重命名我们的枚举常量)。因此,我的问题是:除了简单地重命名枚举常量以避免这种命名冲突,还有其他(优选)方法来解决此问题吗?使用名称空间似乎不起作用。避免预定义的数字常量与C++中的枚举相冲突
更新版(命名空间): 我得到这个错误:
enum.cpp:5:5: error: expected identifier before numeric constant
enum.cpp:5:5: error: expected ‘}’ before numeric constant
enum.cpp:5:5: error: expected unqualified-id before numeric constant
enum.cpp:7:1: error: expected declaration before ‘}’ token
该程序:
#include <sys/ioctl.h>
namespace mine {
enum test {
NCC
};
}
int main(int argc, char** argv)
{
return 0;
}
注意,我得到编译该程序时同样的错误:
#define NCC 5
namespace mine {
enum test {
NCC
};
}
int main(int argc, char** argv)
{
return 0;
}
请说明如何应用命名空间,以便我们诊断它。 – wallyk
如果它是与你碰撞的预处理器符号,命名空间将无济于事。 –
现在更新了名称空间似乎不起作用的方式。 – t2k32316