Sign in to follow this  

Scene Management it says my menu isn't a class or namespace why?

This topic is 3488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm writing a small scene management engine for my game, so i don't have to use a FSM. I was wondering why it's saying that Menu isn't a class or a namespace when I have clearly defined it as a class as far as I know. Here is the code. SM.h & SM.CPP
#ifndef SM_H
#define SM_H

#include <SDL\SDL.h>
#include <vector>
using namespace std;

class GS;

class SM
{
public:
	void init();
	void clean_up();

	void change_state(GS* game_state);
	void push_state(GS* game_state);
	void pop_state();

	void handl_events();
	void update();
	void render(SDL_Surface* screen);

	bool Running() {return m_running;}
	void quit() {m_running = false;}

private:
	vector<GS*> game_states;

	bool m_running;
};
#endif


#include "SM.h"
#include <SDL\SDL.h>
#include "GS.h"

void SM::init()
{

}

void SM::clean_up()
{
	if(!game_states.empty())
	{
		game_states.back()->clean_up();
		game_states.pop_back();
	}
}

void SM::change_state(GS* state)
{
	//clean up last scene
	if(!game_states.empty())
	{
		game_states.back()->clean_up();
		game_states.pop_back();
	}

	//initialize and store new game scene
	game_states.push_back(state);
	game_states.back()->init();
}

void SM::push_state(GS*state)
{
	//pause current state
	if(!game_states.empty())
	{
		game_states.back()->pause();
	}

	//store and init new state
	game_states.push_back(state);
	game_states.back()->init();
}

void SM::pop_state()
{
	//clean up the current state
	if(!game_states.empty())
	{
		game_states.back()->clean_up();
		game_states.pop_back();
	}

	//reume previous state
	if(!game_states.empty())
	{
		game_states.back()->resume();
	}

}

void SM::handl_events()
{
	game_states.back()->handle_events(this);
}

void SM::update()
{
	game_states.back()->update(this);
}

void SM::render(SDL_Surface* screen)
{
	game_states.back()->render(screen);
}


This is the class\object I will create in main that will manage the scene the "game state" that the user will be at. A simple stack program that's it. Here is GS.H & Menu.h & I didn't make Menu.cpp, for I was getting Menu isn't a class or namespace and was wondering why I was getting that
#ifndef GS_H
#define GS_H

#include "SM.h"
#include <SDL\SDL.h>
#include <SDL\SDL_image.h>
#include "Gfx.h"

class GS
{
public:
	virtual void init() = 0;
	virtual void clean_up() = 0;
	virtual void pause() = 0;
	virtual void resume() = 0;

	virtual void handle_events(SM* scene) = 0;
	virtual void update(SM* scene) = 0;
	virtual void render(SDL_Surface* screen) = 0;

	void change_state(SM* scene, GS* state) { scene->change_state(state);}

	void what_is_this();

protected:
	GS() {}
};

#endif


#ifndef MENU_H
#define MENU_H

#include "GS.h"


class menu : public GS
{
public:
	void init();
	void clean_up();

	void pause();
	void resume();

	void handle_events(SM* scene);
	void update(SM* scene);
	void render(SDL_Surface *screen);

	static Menu* Instance() { return &m_menu;}

protected:
	menu();

private:
	static Menu m_Menu;

	SDL_Surface *bg;

};
#endif



I think I have the error in this header file some where, but I can't detect it. I was wondering why the intellisense wasn't coming on when I was making the Menu.cpp source file. Please let me know what you would do in this situation. Oh and ps I have a Gfx file where I return and pass the screen from Gfx to whatever scene needs it. For I have developed this huge singleton Gfx class that I don't really like to change as I have it organized and working just fine. Thanks for the replies ;)

Share this post


Link to post
Share on other sites
It looks to me like you've named the class menu, but are referring to a class named 'Menu' within the code.

Also, don't use 'using' directives in header files (if you search the forums for 'using namespace' you should be able to find more details on this).

Share this post


Link to post
Share on other sites
Quote:
Original post by Cwiddy
Possibly that you have that class name as menu not Menu? (unless it is just a typo in yout post)


stupid stupid me I didn't include "Menu.h" when working with the source file

ha ha lol you can all laugh at me now.

Edit:

That was one of the reasons, but now it's still not coming up as a class or a namespace when I try to add it to the SM change_state();

Why? i don't know possibly some further investigation.

Share this post


Link to post
Share on other sites

This topic is 3488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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