• Advertisement
Sign in to follow this  

classes

This topic is 4439 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

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
Advertisement
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
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
Sign in to follow this  

  • Advertisement