Jump to content
  • Advertisement
Sign in to follow this  
Ceoddyn

VC++ Errors =^(

This topic is 4366 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

Ok, I'm trying to make a generic Menu class for helping with console output in my project I'm working on, and I've run into an error I can't get my head around. Here's the code:
//Menu.h
//Class: Menu
//Helper class for making menus.

class MenuOption;

class Menu
{
private:
	std::string m_Title;
	vector<MenuOption> m_Options;
	int m_OptionsAmount;
	char m_Input;

	//get input for the menu, called from displaymenu
	char GetInput();
public:
	//Create the menu with a given title or default string
	Menu(std::string Title="Default String");
	~Menu();
	//Add an option to the menu
	void AddOption(std::string name, char value);
	//Remove an option from the menu
	void RemoveOption(int key);

	//Set/Get the title of the menu
	void SetTitle(std::string title);
	std::string GetTitle();

	//Get the amount of options in the menu
	int GetAmount();

	//Display the menu
	void DisplayMenu();
};


The bad line apparently is:
	vector<MenuOption> m_Options;
which is giving me the following errors:
------ Build started: Project: colormenu, Configuration: Debug Win32 ------
Compiling...
Menu.cpp
c:\c++\tut\tut7\colormenu\Menu.h(11) : error C2143: syntax error : missing ';' before '<'
c:\c++\tut\tut7\colormenu\Menu.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\c++\tut\tut7\colormenu\Menu.h(11) : error C2238: unexpected token(s) preceding ';'

This is my first time working with vectors so I'm probably doing something wrong. Anyone got any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Did you #include <vector>? Also, since this is a header file, it would be best if you used std::vector instead of importing std(::vector) into the global namespace.


jfl.

Share this post


Link to post
Share on other sites
In order for the compiler to deduce the correct template settings it needs the full definition of MenuOption. You only provided it the forward declaration. That's simply not enough for a template.

You can either

A) Include MenuOption.h

or

B) Change the menu class to work with MenuOption pointers instead (std::vector<MenuOption*>).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!