Invalid covariant type with CRTP clonable class

前端 未结 3 1937
眼角桃花
眼角桃花 2020-12-20 19:27

I\'m trying to implement a Clonable class with the CRTP. However, I need to have abstract class that have a pure virtual clone method, overridden by child classes. To make t

3条回答
  •  半阙折子戏
    2020-12-20 20:21

    I think the problem is that

    T* clone() const override{
        return new T{*dynamic_cast(this)};
    }
    

    returns B* instead of AbstractClonable *.

提交回复
热议问题