Bar testFunc() {
Foo foo; // Bar is constructed here
return foo.bar(); // prvalue is move-constructed and copy elided
}
Bar test = testFunc(); // default ctor + move ctor (one copy elision)
总共执行一次副本删除。
将成员移出看起来像是代码的味道。不知道具体用法很难判断,但可能:
Bar make_bar(const Foo& foo) {
Bar bar;
// init bar as needed
return bar;
}