missing storage-class or type specifiers

Started by
12 comments, last by Zahlman 18 years, 9 months ago
I get these errors:

d:\Documents\CPP\Visual Studio Projects\TileSystem\Game.h(30) : error C2143: syntax error : missing ';' before '*'
d:\Documents\CPP\Visual Studio Projects\TileSystem\Game.h(30) : error C2501: 'Game::Console' : missing storage-class or type specifiers
d:\Documents\CPP\Visual Studio Projects\TileSystem\Game.h(30) : error C2501: 'Game::Console' : missing storage-class or type specifiers

On this line: Console* Console; // for the console Im trying to do a console and for some reason it seems not to recognice my console class. Console.h is included and the class is defined there, if it wasnt it should state other errors to, shouldnt it? What could be wrong?
Advertisement
Console * console;
This space for rent.
Console * Console; == Console* Console;

Right?
"Console * console" != "Console * console" (case matters).
I changed the line to this but I still gets the exact same errors... you sure thats whats wrong?

Console * console; // for the console
Console * Console;


Is fine in C++, as is

Console *Console;


And

Console* Console;


The only problem with doing this is that it hides the Console class for the rest of the scope in which the Console variable is defined. For example

class Console{...};int main(){  Console * Console;  Console * Console2;}


Here the Console * Console2; line will give you an error, as it thinks Console is now a variable of type pointer, and interprets Console * Console2; as a multiplication, since Console2 has not been previously defined, you get an error.

There is a way around this, you can qualify the second Console definition with the class keyword, that will tell the compiler that Console refers to a class, and not a variable of type pointer.

class Console{...};int main(){Console * Console;class Console * Console2;}


This now compiles. This is an example of using an 'elaborated type specifier'. You will need to post more code describing the problem.
Yup, thanks, that solved it. But on the line above I have

FontSystem* Font; // for printing text on the screen

Which works fine, why not the console? I couldnt find anywhere in the project where I did make another Console class as you showed there.
Quote:Original post by Mizipzor
Yup, thanks, that solved it. But on the line above I have

FontSystem* Font; // for printing text on the screen

Which works fine, why not the console? I couldnt find anywhere in the project where I did make another Console class as you showed there.


In this case it is likely that the elaborated type specifier simply declared the Console class as existing somewhere in the project. This suggests that you have not actually included the Console header file in the .cpp file that the line of code Console * Console exists in. It is worth you double checking.
Console.h is included.

Game.h (as you can see, the console is at the top and I got other class pointers working fine)
#ifndef _GAME#define _GAME#include <SDL.h>#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <windows.h>#include "SdlHandle.h"#include "Player.h"#include "AsciiMap.h"#include "Log.h"#include "Defines.h"#include "FontSystem.h"#include "Console.h"class Game {protected:	// Singleton class	static Game* m_pInstance;	Game( void );private:	SdlHandle*	Sdl;			// for the graphics	Player		Player;			// the player	AsciiMap	AsciiMap;		// the tiles represented by chars	Log			Log;			// for the logs	FontSystem*	Font;			// for printing text on the screen	class Console*	Console;		// for the Console		bool		running;		// is the game running	Uint8*		keys;			// to keep track of the keys	SDL_Event	event;			// event tracker (keys)public:	// Singleton ---	static Game* GetInstance( void ) {		if ( !m_pInstance )			m_pInstance = new Game();		return m_pInstance;	};	// init stuff ---	bool	InitVideo();		// init graphics	// main stuff --- 	void	RenderWorld();		// draws all the tiles	void	MainLoop();			// the main loop	void	RawCommand(std::string Command);	// for recieving raw commands from the Console};#endif
Its possible you could have some circular dependancy issues. Does the Console.h file include the Game.h header file too?

This topic is closed to new replies.

Advertisement