Sign in to follow this  
xg0blin

What the hell is wrong here?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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
};

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Chozo
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.

They didn't take it out. It never existed in any C or C++ standard until 1999, which is after the lastest C++ standard.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this