Sign in to follow this  
JasonL220

classes

Recommended Posts

JasonL220    132
I have a class that has a function which create a different class eg: class: { class() createImage() modifyImage() ... private: ... } createImage() { image Image(); } modifyImage() { image.change(); } hope you understand :P would that work? btw i'm using C++

Share this post


Link to post
Share on other sites
acraig    471
Showing stuff without context makes it hard to give a good answer here. Why not just use the Image class directly? If you want to have a class that can create other classes you may want to google the Factory design pattern.

==========
Andrew

Share this post


Link to post
Share on other sites
Rycross    584
Well the code you posted wouldn't exactly work, but what you're thinking of is called a factory pattern.


public class Factory
{
...
Widget * createWidget() { return new Widget(); }
AnotherWidget * createAnotherWidget() { return new AnotherWidget(); }
};


etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this