@paddy In your example, I think it would be more illuminating to not use auto for the shared pointers; also, I would let
Create()
make return a shared_ptr of the actually created type, i.e. static std::shared_ptr<Derived> Create()
. Due to shared_ptr's covariance, one can still use it to initialize a shared_ptr<Base>
with it. Here is a minimally modified variation of your code.