Click here to Skip to main content
14,699,491 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I get this error code when trying to make an enum for my game and use it.
"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int"

Project Type: Win32 Blank Project
IDE: Visual Studio 2010
OS: Windows 7 32bit.

My Code:
Here's all my code:

//===============================================
#include "DragonFireSDK.h"
//===============================================
GameState gameState = MainMenu;
//
//  All of the below errors are for the above line of code.
//
//Error	1	error C2146: syntax error : missing ';' before identifier 
//Error	2	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	
//Error	3	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	
//Error	4	error C2065: 'MainMenu' : undeclared identifier	
//
int MainMenu_StartGame_Btn;
int MainMenu_Background_Img;
int View;
//===============================================
enum GameState
{
	MainMenu,
		LevelSelect,
		DifficultySelect,
		CountDown,
		GamePlaying,
		GameEnd,
	Options,
	HighScores,
	Credits
};
struct Player
{
	char Name[20];
	int Score;
};
//===============================================
void AppMain()
{	
	LandscapeMode();
	gameState = MainMenu;
	MainMenu_Background_Img = ImageAdd("Images\\Background.png");
	View = ViewAdd(MainMenu_Background_Img,0,0);
}
//===============================================
void OnTimer()
{
	switch(gameState)
	{
	case MainMenu:
		
		break;
	case LevelSelect:

		break;
	case DifficultySelect:

		break;

	case CountDown:

		break;
	case GamePlaying:

		break;
	case GameEnd:

		break;
	case Options:

		break;
	case HighScores:

		break;
	case Credits:

		break;
	}
}
//===============================================
void AppExit()
{

}
//===============================================
Posted
Updated 7-Jul-12 23:22pm
v3

GameState gameState = MainMenu;

You are declaring a variable of type GameState but you have not told the compiler what a GameState is. you need to define the type before you try to use it. I would also recommend you read carefully the advice provided by Sergey Alexandrovich[^].
   
Comments
   
This is possible, my 5.
--SA
Albert Holguin 9-Jul-12 13:04pm
   
That's the main problem... +5
Remove this "typedef" and you will be fine. :-)

[EDIT #1]

Why are you writing something which you do not understand. Your typedef does not define a type, it simply introduces a new name for the type, an alias:
typedef type_definition new_alias_name_for_this_type
//for example:
typedef int my_integer_type_I_want_to_use;

After you do it, you can use my_integer_type_I_want_to_use instead of int; and the purpose if this is: you can quickly change your decision to use int. For example, if you decide to use unsigned int instead, it can be done in one line where you define my_integer_type_I_want_to_use.

In your case, enum MyType { A, B } is already a complete type definition. If you use typedef before it (you could, but why?), this constructs needs an alias type name at the end, which is missing. Is it clear now?

Please see:
http://en.wikipedia.org/wiki/Typedef[^].

[EDIT #2]

Original question was about enum declaration: OP tried to define it with redundant typedef before enum. After my first answer, the question was changed.

—SA
   
v3
Comments
shelby67 8-Jul-12 4:09am
   
still doesn't work. same error.
   
First understand what are you writing. Please see my update, after [EDIT].
--SA
   
And -- is it C++ or C?
(Forget it, I see it is C++, but the compiler message. Anyway, this is not nice: you ask about C++ and tag both C++ and C. Want us to do a guesswork?)
--SA
shelby67 8-Jul-12 4:12am
   
[Redundant code removed -- SA]
   
Should I count your lines? Comment the error message right on the line of your code, and put this code in the question using "Improve question" above.
--SA
   
Can you see that it has nothing to do with your original question about enum? This must be a bug in a header file. First of all, your forgot ";" at the end (it could be a class declaration).
--SA
shelby67 8-Jul-12 4:31am
   
NEEED HELP.
I don't think this has to do with the header file at all. I'm lead to believe this because if I open up a blank project and try to use an enum, I get the same error. And that's with out the header file.
   
You can think whatever you want...
--SA
   
Please listen. You cannot develop software by trial-and-error. You need to understand each line you are writing...
--SA
[no name] 8-Jul-12 9:24am
   
@shelby67
Don’t vote 1 only because you are not able to follow the instructions.
   
Thank you.
--SA
[no name] 8-Jul-12 15:41pm
   
You’re welcome. I learned a lot from you and the others authorities (Richard MacCutchan, OriginalGriff , Wes Aday, several Kulkarni ;) and _a lot more_) here. At the beginning I think I was similar like shelby67, but with time I recognized, that I can learn here and I take this opportunity ;)
Regards, Bruno
   
Thank you very much for your nice words, Bruno, as well as for your understanding, which is the most important thing.
--SA
Albert Holguin 9-Jul-12 13:07pm
   
People use typedefs a lot because they don't realize that it was used in C before to overcome the need to specify something as an enum... since they copy code off the net without knowing the purpose, you end up with these issues. +5 for the advice...
   
Unfortunately, such things happen. That's why I mentioned in my argument to Shelby that she needs to understand each like she writes.
Thank you, Albert.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900