【发布时间】:2012-12-13 10:16:24
【问题描述】:
假设我们有一个效用函数:
std::string GetDescription() { return "The description."; }
返回字符串字面量可以吗?隐式创建的std::string 对象是否被复制?
我想过总是这样退货:
std::string GetDescription() { return std::move(std::string("The description.")); }
但它当然更长更冗长。我们也可以假设编译器 RVO 会对我们有所帮助
std::string GetDescription() { return std::string("The description."); }
然而,我不知道它真正必须做什么,而不是可以做什么。
【问题讨论】: