在一个接受右值的函数内,再调用一个函数,原右值会自动变成左值

#include<iostream>
using namespace std;
class A{
public:
	A()=default;
	A(int&&a){moves(a);}
void moves(int &a)
{
	t=a;
	cout<<t<<endl;
}

private:
	int t;
};
int main()
{
	A(33);
}

如代码所示,A构造函数内,原右值a自动变成左值(不是通过拷贝构造函数或者移动构造函数),因此moves只能是接受左值,不能接受右值,因为a变成左值了

猜你喜欢

转载自blog.csdn.net/hgtjcxy/article/details/80285118