【发布时间】:2013-11-21 04:52:22
【问题描述】:
//old school '98 c++, no C++0x stuff
std::string getPath();
void doSomething()
{
const std::string &path = getPath(); //const reference to an rvalue
... // doSomething with path
}
void doSomething2()
{
const std::string path = getPath(); //regular variable
... // doSomething with path
}
doSomething 和 doSomething2 有什么区别,哪个更受欢迎?
在 doSomething 中使用 const 引用返回的右值是否安全?
doSomething2 是否创建返回的右值的副本,编译器是否允许在这里进行右值优化?
【问题讨论】:
标签: c++