Here is my issue. I'm creating my own GUI Api. All the Widgets are in a container which has add and remove functions. The widgets derive from a base widget class. Here is where I'm unsure. I would ideally like a flow like this: user creates a (desired widget deriving from base class) pointer, the container allocates and manages resources, the user has a pointer to the widget and can make calls to it.
However, polymorphism makes this confusing. How could I get my container to create the right type of new? The issue here is that anyone can create a new widget (like SuperTextBoxWidget) which is why supplying a string and doing a switch would not solve this.
My other quick-fix alternative is to make the user responsible for doing the new, and providing the pointer to the container's add function. But this does not feel idiot proof to me, and it seems odd to have the user do the initial allocation, but then the container manages the rest including erasure.
What would be the best and cleanest way to go about this?
Thanks
just an idea of what I have so far:
class AguiWidgetContainer
{
std::vector<AguiWidgetBase*> widgets;
public:
AguiWidgetContainer(void);
~AguiWidgetContainer(void);
void handleEvent(ALLEGRO_EVENT* event);
int add(AguiWidgetBase *widget);
bool remove(int widgetId);
};