What the hell is wrong here?

Started by
9 comments, last by Polymorphic OOP 19 years, 4 months ago
I've used this library of mine before. Many times. It's never given me an error, but for some reason now doesn't like my enum. Take a look, I'll number the lines for you so you can read the error messages. This is all I got in this file down to the error (there is a lot more below but I won't bother posting it):

12. #ifndef BMP_H
13. #define BMP_H
14.
15. #include "XGTypes.h"
16. #include <string>
17. #include <fstream>
18. #include <cmath>
19. using namespace std;
20.
21. enum IMAGETYPE 
22. {
23.	BI_RGB = 0, 
24.	BI_RLE8, 
25.	BI_RLE4, 
26.	BI_BITFIELDS, 
27.	BI_JPEG, 
28.	BI_PNG,
29. };

The errors are as follows: 1. e:\DOCUMENTS AND SETTINGS\crosslra\My Documents\Visual Studio Projects\TileMapViewer\BMP.h(23): error C2143: syntax error : missing '}' before 'constant' 2. e:\DOCUMENTS AND SETTINGS\crosslra\My Documents\Visual Studio Projects\TileMapViewer\BMP.h(29): error C2143: syntax error : missing ';' before '}' 3. e:\DOCUMENTS AND SETTINGS\crosslra\My Documents\Visual Studio Projects\TileMapViewer\BMP.h(29): error C2059: syntax error : '}' 4. e:\DOCUMENTS AND SETTINGS\crosslra\My Documents\Visual Studio Projects\TileMapViewer\BMP.h(23): error C2143: syntax error : missing '}' before 'constant' 5. e:\DOCUMENTS AND SETTINGS\crosslra\My Documents\Visual Studio Projects\TileMapViewer\BMP.h(29): error C2143: syntax error : missing ';' before '}' 6. e:\DOCUMENTS AND SETTINGS\crosslra\My Documents\Visual Studio Projects\TileMapViewer\BMP.h(29): error C2059: syntax error : '}' In short, they all point to my enum, and I can't figure out for the life of me why.
Advertisement
You have recently included a file (suspect: wingdi.h) which #define's the enum field names to be something (i.e. constants) so you end up with the preprocessor munging the code and the compiler seeing something like
enum
{
12 = 0
};
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
and get rid of the comma after BI_PNG :p
What other headers are included before bmp.h? I can reproduce that error by including a #define BI_RGB 0 before the definition of IMAGETYPE, so I assume that some other header you're including is doing exactly this.

Enigma
The comma after BI_PNG isn't there. Sorry about that. Typo.

Anyways, here are the files I have included and the files that are included in them.

#include "XGTypes.h"
#include <string>
#include <fstream>
#include <cmath>

nothing is included in XGTypes, so it would have to be something included somewhere else or something.

In the whole app, it's these:
#include <windows.h>
#include <GL/glut.h>
#include "MapReader.h"
#include <string>
#include <vector>
#include <fstream>
#include <GL/gl.h>
#include "BMP.h"
#include "XGTypes.h"

That's all of the include files from the whole project so far, scattered about in different areas.
I just moved the order of the includes around and got it. Thanks. It must have been defined in one of the files included in windows.h, or glut.h.
Quote:Original post by Polymorphic OOP
and get rid of the comma after BI_PNG :p


There a reason why? The comma there is perfectly legal and allows for automated addition of enumerated constants.
Apparently the trailing comma should only be allowed in C, and should be illegal in C++. I always use a trailing comma to make it easy to add an extra entry to the end of the enum, unless the last entry should be the last such as in
enum PrimaryColours
{
RED,
GREEN,
BLUE,
LAST_PRIMARY_COLOUR
};

but apparently that shouldn't be allowed (although VC6 allows it).
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Quote:Original post by Chozo
Quote:Original post by Polymorphic OOP
and get rid of the comma after BI_PNG :p


There a reason why? The comma there is perfectly legal and allows for automated addition of enumerated constants.

As Paradigm Shifter said, trailing commas are not legal. This is C++, not C99.
Huh, that's crazy. Why would they take out something like that? I haven't come across a C++ compiler that treats it as an error.

This topic is closed to new replies.

Advertisement