Undeclared class

This is a discussion on Undeclared class within the C++ Programming forums, part of the General Programming Boards category; Hey guys. I just started a few minutes ago working on a project and I think I've hit an interesting ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    903

    Undeclared class

    Hey guys. I just started a few minutes ago working on a project and I think I've hit an interesting problem. I'm trying to use a friend's idea and make pure virtual base classes and inherit from them to make portable versions (i.e. you make a windows_gui_object or unix_gui_object inherit from basic_gui_object and such). However, I think I've hit a design flaw, here's the code:
    Code:
    namespace gui
    {
    	class basic_gui_object;
    	class basic_gui_surface : public basic_gui_object;
    
    	class basic_gui_object
    	{
    	public:
    		basic_gui_object();
    		virtual ~basic_gui_object();
    
    		virtual void Render(basic_gui_surface*) = 0;
    		void SetPosition(int, int);
    	public:
    		int x, y;
    	private:
    		static std::list<basic_gui_object*> ObjList;
    	};
    }
    The compiler complained that it didn't know what basic_gui_surface was, so I pre-declared it but then, since basic_gui_surface inherits from basic_gui_object, it complained about basic_gui_object not being declared... so I pre-declared basic_gui_object as well and now it complains about basic_gui_object not being defined... I've tried adding braces at the end of each pre-declaration and -- of course -- I have defined basic_gui_object (without defining Render(), indeed). How could I fix this annoying problem ?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,438
    You only need to declare basic_gui_surface as

    Code:
    class basic_gui_surface;
    It's the basic_gui_surface definition that needs the derivation list.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    Hey, thanks !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  3. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

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