We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
输出结果为:
传递右值: 普通传参:左值引用 std::move 传参:右值引用 std::forward 传参:右值引用 传递左值: 普通传参:左值引用 std::move 传参:右值引用 std::forward 传参:左值引用
无论传递参数为左值还是右值,普通传参都会将参数作为左值进行转发,所以 std::move 总会接受到一个左值,从而转发调用了reference(int&&) 输出右值引用。
std::move 总会接受到一个左值 ,但从上面的结果来看应该是右值吧?
The text was updated successfully, but these errors were encountered:
这个过程需要仔细阅读代码,正文中的介绍可能不够详细,会在支持 C++17 的过程中修订这部分内容:
从普通传参 中可以看看出 reference(v); 始终是调用的左值引用,所以对于 void pass(T&& v) 内而言,v 是一个左值。std::move 的作用在于将一个左值转化为一个右值,这一点可以从 std::move 传参 的输出结果中得到验证。
普通传参
reference(v);
void pass(T&& v)
v
std::move
std::move 传参
Sorry, something went wrong.
No branches or pull requests
std::move 总会接受到一个左值 ,但从上面的结果来看应该是右值吧?
The text was updated successfully, but these errors were encountered: