Hey all.
I’m trying to write my own (very simple) GUI framework. I’ve worked with flash alot, so i was
thinking of making it a flash-esque type of framework. I want to split the framework into
two base classes being UIComponent (Buttons, Sliders etc) and UIComponentContainer (Views, Panels etc).
The problem i’m having is that i would like to cross-reference these two classes. For example:
class UIComponent : public EventDispatcher
{
public:
UIComponentContainer* m_Parent;
};
class UIComponentContainer : public UIComponent
{
private:
std::list<UIComponent*> m_Children;
};
The reason for UIComponentContainer to extend UIComponent is that I want to keep most
of the functionallity in the component class and simply extend it so that it can also contain
other components.
I’ve been googling alot about this and have learned that you can forward declare classes,
so just before including a header file you declare the class inside the file to be included, like so
class UIComponentContainer;
#include "UIComponentContainer.h"
However I must be doing this wrong since it’s not helping at all, i still get the classic
cross-referencing error. How can I achieve this type of cross-referencing and is it a wise
thing to do at all or should I rethink the way I manage my components?
- Edvin