Sign in to follow this  
Jaiminho

Virtual Constructor Idiom

Recommended Posts

Jaiminho    184
[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
Sneftel    1788
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
Jaiminho    184
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

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