fork download
#include 

    struct Cloneable
    {
    protected:
        Cloneable(){}
        Cloneable(const Cloneable &){}
    public:
        virtual ~Cloneable(){}

        Cloneable &operator=(const Cloneable &) = delete;

        virtual Cloneable *Clone() const = 0;
        template
        static void ReleaseClone(TextendsCloneable *&clone)
        {
            Cloneable *c = dynamic_cast(clone);
//          if(!c) throw CloningException();
            clone = /*nullptr*/0;
            c->ReleaseClone(), c = /*nullptr*/0;
        }
    protected:
        virtual void ReleaseClone() = 0;
    public:
//        struct CloningException : public virtual Exception
//        {
//            CloningException(){}
//            CloningException(const char *msg) : Exception(msg) {}
//            CloningException(const CloningException &) = delete;
//            CloningException &operator=(const CloningException &) = delete;
//            virtual ~CloningException(){}
//        };

        template
        struct Auto;
    };
    
    template
    struct Cloneable::Auto : public virtual Cloneable
    {
        virtual InheritingClass *Clone() const
        {
            const InheritingClass *t = dynamic_cast(this);
            if(!t)
            {
//                    throw CloningException();
            }
            return new InheritingClass(*t);
        }
    protected:
        virtual void ReleaseClone()
        {
            if(!dynamic_cast(this))
            {
//                    throw CloningException();
            }
            delete this;
        }
    public:
        virtual ~Auto(){}
    };

struct MyAbstractClass : public virtual Cloneable
{
    MyAbstractClass(){}
    MyAbstractClass(const MyAbstractClass &){}
    virtual ~MyAbstractClass(){}
    
    MyAbstractClass &operator=(const MyAbstractClass &) = delete;

    virtual void Tick() = 0;
};

struct MyImplementationClass : public virtual MyAbstractClass, public virtual Cloneable::Auto
{
    MyImplementationClass(){}
    MyImplementationClass(const MyImplementationClass &){}
    virtual ~MyImplementationClass(){}
    
    MyImplementationClass &operator=(const MyImplementationClass &) = delete;
    
    virtual void Tick();
    
//    using Cloneable::Auto::Clone;
//protected:
//    using Cloneable::Auto::ReleaseClone;
};

void MyImplementationClass::Tick()
{
    std::cout << "Tick" << std::endl;
}

int main()
{
    MyImplementationClass a;
    MyAbstractClass *b = a.Clone();
    b->Tick();
    Cloneable::ReleaseClone(b);
}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'Cloneable::Auto<MyImplementationClass>':
prog.cpp:75:1:   instantiated from here
prog.cpp:41:34: error: invalid covariant return type for 'InheritingClass* Cloneable::Auto<InheritingClass>::Clone() const [with InheritingClass = MyImplementationClass]'
prog.cpp:13:28: error:   overriding 'virtual Cloneable* Cloneable::Clone() const'
stdout

Standard output is empty