Crazy errors caused by class, never seen before..

This is a discussion on Crazy errors caused by class, never seen before.. within the C++ Programming forums, part of the General Programming Boards category; The code: Code: #ifndef Menu #define Menu #include "Object.h" #include <string> #include <list> class Menu : public CObject { public: ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Crazy errors caused by class, never seen before..

    The code:

    Code:
    #ifndef Menu
    #define Menu
    
    #include "Object.h"
    #include <string>
    #include <list>
    
    class Menu : public CObject
    {
    public:
    	Menu(std::string mSelection) 
    	{
    		mSelection = Selection;
    	}
    
    	virtual ~Menu() { Destroy(); }
    
    	// deletes self
    	void Release() { delete this; }
    
    	// call update on all children
    	virtual void Update()
    	{
    		for( std::list<Menu*>::iterator i = MenuChoices.begin();
    			i != MenuChoices.end(); i++ )
    		{
    			(*i)->Update();
    		}
    	}
    
    	// recursively destroy all children and self
    	void Destroy()
    	{
    		for( std::list<Menu*>::iterator i = MenuChoices.begin();
    			i != MenuChoices.end(); i++ )
    		(*i)->Release();
      
    		MenuChoices.clear();
    	}
    
    	// add a child
    	void MenuSelection( Menu* MenuSelection )
    	{
    		MenuSelection->SetRootMenu(this);
    	    MenuChoices.push_back(MenuSelection);
    	}
    
    	// Set the parent of the child
    	void SetRootMenu(Menu* Root)
    	{
    		RootMenu = Root;
    	}
    
    protected:
    	// list of children
    	std::list<Menu*> MenuChoices;
    	// pointer to parent
    	Menu * RootMenu;
    
    	std::string Selection;
    
    };
    #endif
    The errors
    Code:
    ------ Build started: Project: TextGame, Configuration: Debug Win32 ------
    Compiling...
    Main.cpp
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(12) : error C2473: 'mSelection' : looks like a function definition, but there is no parameter list.
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(13) : error C2065: 'Selection' : undeclared identifier
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(13) : error C2864: '<unnamed-tag>::mSelection' : only static const integral data members can be initialized within a class
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(16) : error C2059: syntax error : '('
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(16) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(16) : error C2447: '{' : missing function header (old-style formal list?)
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(19) : error C2673: 'Release' : global functions do not have 'this' pointers
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(23) : error C2575: 'Update' : only member functions and bases can be virtual
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(24) : error C2059: syntax error : '>'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(24) : error C2039: 'iterator' : is not a member of '`global namespace''
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(25) : error C2059: syntax error : ')'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(26) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(28) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(29) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(33) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(34) : error C2059: syntax error : '>'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(34) : error C2039: 'iterator' : is not a member of '`global namespace''
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(35) : error C2059: syntax error : ')'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(39) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(43) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(46) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(50) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(52) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(56) : error C2059: syntax error : '>'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\menu_object.h(62) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\database.h(7) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\database.h(10) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\interpreter.h(10) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\interpreter.h(16) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\interpreter.h(17) : error C2653: 'Command_List' : is not a class or namespace name
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\interpreter.h(20) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\interpreter.h(22) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\interpreter.h(35) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\interpreter.h(40) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\main.cpp(4) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\main.cpp(7) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\main.cpp(8) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\main.cpp(8) : fatal error C1004: unexpected end-of-file found
    Build log was saved at "file://c:\Documents and Settings\Home\My Documents\Visual Studio 2005\Projects\TextGame\TextGame\Debug\BuildLog.htm"
    TextGame - 39 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Nevermind, my #ifndef and #define were wrong. Solved.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Since we're here, take another look at your constructor. Besides the fact that I would use initializer lists, you've got something backwards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM

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