【发布时间】:2013-06-13 02:11:00
【问题描述】:
静态转换的描述说
如果 new_type 是右值引用类型,static_cast 将表达式的值转换为 xvalue。这种类型的 static_cast 用于在 std::move 中实现移动语义。(C++11 起)
这是否确认以下是等价的?
(A)
X x1;
X x2 = static_cast<X&&>(x1);
(B)
X x1;
X x2 = std::move(x1);
【问题讨论】:
-
它们是等价的,但 move 不太容易出错。
标签: c++ c++11 move static-cast