相关疑难解决方法(0)

在 C++ 中保持对函数返回值的常量引用

如果我在 C++11 中保持对函数的非引用返回值的常量引用,那么堆栈中的引用点在哪里?这样做安全吗?

string foo() {
  std::string foo_ret = "foo string";
  return foo_ret;
}

int main() {
  const std::string& a = foo();
}
Run Code Online (Sandbox Code Playgroud)

c++ reference return-value c++11

4
推荐指数
1
解决办法
1258
查看次数

标签 统计

c++ ×1

c++11 ×1

reference ×1

return-value ×1