Click here to Skip to main content
15,888,733 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:

C++
//===============================================
#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 22:22pm
v3

C++
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[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jul-12 13:43pm    
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:
C#
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
 
Share this answer
 
v3
Comments
shelby67 8-Jul-12 4:09am    
still doesn't work. same error.
Sergey Alexandrovich Kryukov 8-Jul-12 4:10am    
First understand what are you writing. Please see my update, after [EDIT].
--SA
Sergey Alexandrovich Kryukov 8-Jul-12 4:12am    
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]
Sergey Alexandrovich Kryukov 8-Jul-12 4:16am    
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

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