Vererbungsproblem



  • Hallo,

    erstmal die (absolut) reduzierten Klassen:

    gui.h:
    #ifndef __CONTROL_H__
    #define __CONTROL_H__
    
    #include <windows.h>
    
    namespace Gui
    {
    	class Form;
    
    	class Control
    	{
    	public:
    		Control(Form *parent = NULL);
    		virtual ~Control();
    
    	protected:
    		Form *f;
    	};
    }
    
    //#include "form.h"
    
    #endif
    
    gui.cpp:
    #include "control.h"
    
    namespace Gui
    {
    	Control::Control(Form *parent)
    	{
    		f = NULL;
    	}
    	Control::~Control()
    	{
    
    	}
    }
    
    label.h:
    #ifndef __LABEL_H__
    #define __LABEL_H__
    
    #include "control.h"
    
    namespace Gui
    {
    	class Label : public Control
    	{
    	public:
    		Label(Form *parentForm = NULL);
    	};
    }
    
    #endif
    
    label.cpp:
    #include "label.h"
    
    namespace Gui
    {
    	Label::Label(Form *parent)
    	{
    		f = parent;
    
    		//f->add(this);
    	}
    }
    
    panel.h:
    #ifndef __PANEL_H__
    #define __PANEL_H__
    
    #include "control.h"
    
    namespace Gui
    {
    	class Panel : public Control
    	{
    	public:
    		Panel(Form *parent = NULL);
    	};
    }
    
    #endif
    
    panel.cpp:
    #include "panel.h"
    
    namespace Gui
    {
    	Panel::Panel(Form *parent)
    	{
    		f = parent;
    	}
    }
    
    form.h:
    #ifndef __FORM_H__
    #define __FORM_H__
    
    #include "panel.h"
    
    namespace Gui
    {
    	//class Panel;
    	class Form : public Panel
    	{
    	public:
    		Form();
    
    		void add(Control *c) {}
    	};
    }
    
    #endif
    
    form.cpp:
    #include "Form.h"
    
    namespace Gui
    {
    	Form::Form()
    	{
    		f = this;
    	}
    }
    

    Das funktioniert so wie es da steht. Wenn ich nun in der label.cpp die Zeile f->add(this); einkommentiere (gibts das Wort?! ;)), bekomme ich den Fehler, dass er Form nicht kennt. Soweit auch normal, also das #include "form.h" in der control.h einkommentieren. Jetzt bekomme ich aber den Fehler "error C2504: 'Gui::Panel': Basisklasse undefiniert" in der form.h. Ich verstehe nicht warum, da er ja eigentlich die panel.h vorher includiert. Eine forward decleration per class Panel; in der form.h ändert nichts. Lösen lässt sich das Problem, indem ich die Klassendefinition aus der panel.h in die form.h schreibe. Allerdings würd ich das gern vermeiden, damit alles in der zugehörigen Datei ist.
    Hat jemand ne Idee, wie sich das Problem lösen lässt?

    greetz KN4CK3R



  • #include "form.h" in "control.h" ist ja auch totaler Unfug, wie kommst du darauf?
    Mach das #include "form.h" dort wo du es brauchst, also in "label.cpp".



  • löl, danke für den Hinweis. kA was mich auf dem Auge blind werden lies. 😉

    greetz KN4CK3R


Anmelden zum Antworten