C++ Object Creation

Started by
2 comments, last by s3r1n 19 years ago
Sorry ahead of time if I am not fully able to articulate what it is I am shooting for. I am creating a rather simple GUI system where I would like to have a base GUI manager that handles everything from events to widget instantiation. Instead of having a base button class or derived button class I would like to be able to register a class that fills the roll. Example - class MyButton : public GUIWidget { yada yada... }; GUI.registerWidget("Button", MyButton); ?? Then if I want to create a button.. GUI.create("Button", "button1"); However, I'm finding it difficult to go about doing this without relying on either a non encapsulated function pointer for creation (as in creating a function just for making new MyButton's). What I'm pretty much getting at is what should I pass to register to make it so I can create widgets just by a generic string instead of by it's class. If a function pointer like I stated earlier is the best/only way to do it, then so be it. I would just like to know of the other options to go about it. I'm 100% sure this has been covered many times, but since I really don't know what I'm asking about it's extremely hard to google for this.
Advertisement
Quote:Original post by s3r1n
What I'm pretty much getting at is what should I pass to register to make it so I can create widgets just by a generic string instead of by it's class.


[smile] Those are the magic words for needing an Object Factory. Take a look at that article and play around with the code a bit. If you want to do some more research, you now know what to look for [wink]. If you have eany other questions/comments feel free to ask. I am actively working with this tutorial in my own project, so I have a *decent* understanding of how it works.
As usual, Drew, you give complete answers so nobody else can participate ;)

However, I can still try and suggest looking into managed C++ (which I believe supports reflection) as well.
Thanks Drew, that's exactly what I was looking for.

This topic is closed to new replies.

Advertisement