Jump to content
  • Advertisement
Sign in to follow this  
Jaiminho

Virtual Constructor Idiom

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

[C++] Is there a more elegant way to do a copy of the object pointed by an abstract base class instead of using the Virtual Constructor Idiom?
struct base
{
    virtual ~base() { }

    virtual base* clone() const = 0;
};

Share this post


Link to post
Share on other sites
Advertisement
Not that comes immediately to mind. (Oh, and there's very little reason for a clone() method to be pure virtual.) What do you feel is inelegant about this idiom?

Share this post


Link to post
Share on other sites
I simply thought there could be a way to achieve this without actually having to implement this clone method. By the way, I need the method to be pure virtual in cases of abstract base classes, since i can't call new on it.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!