問題(Question):
https://www.chromium.org/rvalue-references
在上面這個網頁裡,看到這段敘述
However, if the types of the variable and the return type do not match
exactly, then you will have to use std::move() in order to convert without
creating an extra temporary.
std::unique_ptr<MyType> MakeMyType()
{
std::unique_ptr<ChildClassOfMyType> ptr;
// This call to std::move() is needed to convert from a pointer-to-the
// child class to a pointer-to-the parent.
return std::move(ptr);
}
我看不懂的是…為什麼這樣寫可以減少extra temporary呢?
如果不這麼寫的話又會造成什麼問題?
(想知道這個寫法的反例?)