相关疑难解决方法(0)

为什么C++ 11具有值参数的隐式移动,而不是rvalue参数?

在C++ 11中,值参数(和其他值)在返回时享受隐式移动:

A func(A a) {
    return a; // uses A::A(A&&) if it exists
}
Run Code Online (Sandbox Code Playgroud)

至少在MSVC 2010中,右值参考参数需要std::move:

A func(A && a) {
    return a; // uses A::A(A const&) even if A::A(A&&) exists
}
Run Code Online (Sandbox Code Playgroud)

我认为内部函数,右值引用和值的行为类似,唯一的区别是在值的情况下,函数本身负责销毁,而对于右值引用,责任在外面.

在标准中对待它们的动机是什么?

c++ rvalue-reference move-semantics c++11 c++20

21
推荐指数
3
解决办法
3688
查看次数

标签 统计

c++ ×1

c++11 ×1

c++20 ×1

move-semantics ×1

rvalue-reference ×1