std::string 的右值和左值

问题描述

我运行了如图所示的代码,我对为什么 a+b 是右值感到困惑。据我所知,右值应该只有数据或地址,在这种情况下 std::string 应该是左值,不是吗?


void foo(const std::string&& input){
    std::cout<<"RVALUE "<<input<<std::endl;
}
void foo(const std::string& input){
    std::cout<<"LVALUE "<<input<<std::endl;
}

int main(){
    std::string a = "Tom";
    std::string b = "Cruise"; 
    std::string c = a + b;
    foo(a+b);
    foo(c);
}

输出

 RVALUE TomCruise 
 LVALUE TomCruise

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)