Sign in to follow this  

C++ Object Creation

This topic is 4674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this