#include <iostream>
using namespace std;
class A{
public:
int a;
A(int i){a = i;}
A(const A& rhs) // copy constructor
{
a = 2;
}
A(const A&& rhs) // move constructor
{
a = 3;
}
};
void print(A a)
{
cout << a.a << endl;
}
A createA()
{
A a(1);
if( false )
return A(1);
else
return a;
}
int main(){
A a = createA();
print(a);// This will invoker copy constructor and output is 2
print(createA()); // This should invoke move constructor because this object here is rvalue right?
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQXsKcHVibGljOgogICAgaW50IGE7CgogICAgQShpbnQgaSl7YSA9IGk7fQoKICAgIEEoY29uc3QgQSYgcmhzKSAvLyBjb3B5IGNvbnN0cnVjdG9yCiAgICB7CiAgICAgICAgYSA9IDI7CiAgICB9CgogICAgQShjb25zdCBBJiYgcmhzKSAvLyBtb3ZlIGNvbnN0cnVjdG9yCiAgICB7CiAgICAgICAgYSA9IDM7CiAgICB9Cgp9OwoKdm9pZCBwcmludChBIGEpCnsKICAgIGNvdXQgPDwgYS5hIDw8IGVuZGw7Cn0KCkEgY3JlYXRlQSgpCnsKICAgIEEgYSgxKTsKICAgIGlmKCBmYWxzZSApCiAgICAgICAgcmV0dXJuIEEoMSk7CiAgICBlbHNlCiAgICAgICAgcmV0dXJuIGE7Cn0KCmludCBtYWluKCl7CgogICAgQSBhID0gY3JlYXRlQSgpOwogICAgcHJpbnQoYSk7Ly8gVGhpcyB3aWxsIGludm9rZXIgY29weSBjb25zdHJ1Y3RvciBhbmQgb3V0cHV0IGlzIDIgCgogICAgcHJpbnQoY3JlYXRlQSgpKTsgLy8gVGhpcyBzaG91bGQgaW52b2tlIG1vdmUgY29uc3RydWN0b3IgYmVjYXVzZSB0aGlzIG9iamVjdCBoZXJlIGlzIHJ2YWx1ZSByaWdodD8KfQo=