【发布时间】:2017-05-07 01:02:17
【问题描述】:
(A)
std::string doNothing(const std::string&& s)
{
return std::move(s);
}
(B)
std::string doNothing(const std::string& s)
{
return std::move(s);
}
(测试)
const std::string str = "aaaaaa";
const auto str2 = doNothing(str);
两个问题:
- (A)和(B)有区别吗?
- 在(测试)中:str 是未定义的吗?移到 str2 后?
【问题讨论】:
-
您的测试用例不应该编译。左值
str无法绑定到&&。 -
每个问题一个问题。
-
str是const,所以不能修改。见stackoverflow.com/questions/18646874/…
标签: c++ c++11 reference move-semantics