My code run in vs2019,release,x86. Here the constructor of c should be a right-valued reference, why not execute the move constructor but copy constructor?
#include<iostream>
class Test
{
public:
int num{ 0 };
Test(int num1) : num(num1) {}
Test(const Test& rhs)
{
std::cout << "copy\n";
num = rhs.num;
}
Test(Test&& rhs)
{
std::cout << "move\n";
num = std::move(rhs.num);
}
};
int main()
{
Test a(10);
Test&& b = std::move(a);
Test c(b); // copy
Test d(std::move(a)); // move
Test e(static_cast<Test&&>(a)); // move
}
copy move move