Question about enumerations.

I thought that enumerations were just an easy way to have a list or a color code or something along those lines. I'm following a tutorial (game from scratch..pang!). In that tutorial he has an enum MenuResult, but after that he puts it before all of his functions like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class MainMenu
{

public:
	enum MenuResult { Nothing, Exit, Play };	
	
	struct MenuItem
		{
		public:
			sf::Rect<int> rect;
			MenuResult action;
		};
	
	MenuResult Show(sf::RenderWindow& window);

private:
	MenuResult GetMenuResponse(sf::RenderWindow& window);
	MenuResult HandleClick(int x, int y);
	std::list<MenuItem> _menuItems;
};


Then in the code when he is defining the functions he does this.

1
2
3
4
MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window)
{
...
}


1
2
3
4
MainMenu::MenuResult MainMenu::HandleClick(int x, int y)
{
...
}

and so on for all the rest. Can anyone explain how enums can come before functions like that?


EDIT:
This is a link to the tutorial if you want all of the code for whatever reason.
http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-Part-3.aspx
Last edited on
MenuResult is an enum type and those functions have MenuResult as return type. Possible values the functions can return is Nothing, Exit and Play.
Last edited on
MenuResult is a member of the class MainMenu. So when a member of a class is used outside the class scope it shall be prefixed by the class name as, for example, here

1
2
3
4
MainMenu::MenuResult MainMenu::Show(sf::RenderWindow& window)
{
...
}


Any other class may define its own member enum MenuResult.


Topic archived. No new replies allowed.