Is unique_ptr<Derived> to unique_ptr<Base> up-casting automatic?
问题 I know it is possible that a derived class unique_ptr can take place where base class unique_ptr is required for polymorphic types. For example, while returning from function unique_ptr<Base> someFunction() { return make_unique<Derived>(new Derived()); } or passing to function as argument. // Function taking unique pointer void someOtherFunction(unique_ptr<Base>&& ptr) // Code calling this function someOtherFunction(std::move(ptrToDerived)); My question is: Is this upcasting always automatic?