I tested c++11 move function, but not become effective. Who can tell me why ? Thanks. The code is as follows:
class Base {
public:
Base() { cout << "Base" << endl;}
~Base() { cout << "~Base" << endl;}
Base(const Base& base) { cout << "Copy" << endl; }
Base& operator=(const Base& base) {cout << "operator=" << endl;}
Base(Base&& base) { cout << "move" << endl;}
Base& operator=(Base&& base) { cout << "move=" << endl;}
};
Base b;
Base&& GetResult() {
return std::move(b);
}
int main() {
Base&& tmp = GetResult();
cout << &b << endl;
cout << &tmp << endl;
}
Output:
Base
0x6013a0
0x6013a0
~Base
Why move copy
and move operator=
not be called ? And why address is the same ?