Virtual Constructor Idiom

Started by
1 comment, last by Jaiminho 16 years, 6 months ago
[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;
};

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?
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.

This topic is closed to new replies.

Advertisement