What are the drawbacks of C++ covariance return types?
问题 I have recently had to deal with C++ covariance return types such as the following construct : struct Base { virtual ~Base(); }; struct Derived : public Base {}; struct AbstractFactory { virtual Base *create() = 0; virtual ~AbstractFactory(); }; struct ConcreteFactory : public AbstractFactory { virtual Derived *create() { return new Derived; } }; It allows the client code to treat the Derived object as a Base type or as a Derived type when needed and especially without the use of dynamic_cast