So, I’m still working on this big project to make it compiles on Linux. So, again, I got some error that shouldn’t be allow to exist.
Here’s some error that I got:
(1) error: expected identifier before numeric constant
(2) error: "Value" doesn't name a type
Here’s a sample piece of code, simplified, that show you where I get those errors:
class Test
{
public:
enum Value
{
V1 = 0, // error (1) is here
V2 = 1,
V3 = 2
};
private:
Value value; // error (2) is here
public:
// constructor and other function
};
Also, that piece of code is valid in some part of the project. But it’s not in other parts. I did everything, I rename stuff to be sure it was not ambiguous, doesn’t change anything.
Stuck with GCC 4.1.2
The fragment compiles fine with g++ 4.4.3, and I expect it also compiles fine with g++ 4.1.2.
What you’ve encountered is the reason using
#definefor constants is a fundamentally evil thing to do in C++. One of the header files you’ve included incorporates a line like:The fastest solution is
although, if someone has been malicious enough to
#define V1then I sense similar defines forV2andV3in your future. In my personal experiencewindows.hand many of the X11 headers are widely responsible for introducing preprocessor definitions like these.I’d like to offer advice on tracking the offending header down, but I usually resort to grep and/or seeing which headers make the error go away when removed.
When we encounter this problem our general practice is to
#undefs all the offending constants and replaces them with something more reasonable if necessary.