Considering the following code:

#include <iostream>
using namespace std;

struct I {
    I(I&& rv) { cout << "I::mvcotr" << endl; }
};

struct C {
    I i;
    I&& foo() { return move(i) };
    }
};

int main() {
    C c;
    I i = c.foo();
}

C contains I. And C::foo() allows you to move I out of C. What is the difference between the member function used above:

I&& foo() { return move(i) }; // return rvalue ref

and the following replacement member function:

I foo() { return move(i) }; // return by value

To me, they seem to do the same thing: I i = c.foo(); leads to a call to I::I(I&&);.

What consequences will there be that is not covered in this example?

Edit
Report