Move constructor of class accepts rvalue reference which can be reference to temporary object. So, i have temporary object and appropriate move constructor which can accept reference to temporary object, but move constructor does not called. What`s wrong?
//g++ 5.4.0
#include <iostream>
class foo
{
int data;
public:
foo(int v) : data(v) {std::cout << "foo(int)\n";}
foo(foo&& f)
{
std::cout << "moved\n";
}
void print()
{
std::cout << data;
}
};
void acceptTmp(foo f)
{
f.print();
}
int main()
{
foo f1 = foo(100);
f1.print();
acceptTmp(foo(200)); //also does not move
}