问题(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呢?
如果不这么写的话又会造成什么问题?
(想知道这个写法的反例?)