Hi guys, I have small problem with my example code.
Any hint?
#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);
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?
}
Output is:
2
1
Sadly it should be:
2
3
Can't figure it out...