Sign in to follow this  

Virtual Constructor Idiom

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

This topic is 3719 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.

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