I have the following source file (test.c):
#include <iostream>
enum ecodes { ENOKEY = -1, EDUPKEY = -2 };
int main()
{
return 0;
}
When I compile without -std=c++11 it compiles fine.
g++ test.c -o test
When compiled with -std=c++11, it comes with compilation error:
g++ -std=c++11 test.c -o test
test.c:3:16: error: expected identifier before numeric constant
enum ecodes { ENOKEY = -1, EDUPKEY = -2 };
^
test.c:3:16: error: expected â}â before numeric constant
test.c:3:16: error: expected unqualified-id before numeric constant
test.c:3:42: error: expected declaration before â}â token
enum ecodes { ENOKEY = -1, EDUPKEY = -2 };
Compiler used is GNU g++ 4.9.2 on Linux.
bash-4.2$ g++ --version
g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Please help.
ENOKEYis an error code defined in<errno.h>:Presumably
<errno.h>is being#included by<iostream>on your build platform (at least when-std=c++11is specified), so the line:gets preprocessed to:
Hence the error.
Note: your original example code had
INVALIDin place ofENOKEY, so no one else was able to reproduce the problem.Take home message: when asking questions always provide a proper MCVE with actual code that reproduces the error, not an approximation of where you think the problems lies.