此問題與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