小编use*_*645的帖子

返回对本地对象的引用时的编译器警告

如何在不收到警告的情况下返回对象的引用:

std::string& GetString()
{
    std::string str = "Abcdefghijklmnopqrstuvwxyz";
    return str;
}

int main()
{
    std::string str = GetString();
}
Run Code Online (Sandbox Code Playgroud)

这会导致对恭维的警告.

c++ reference

2
推荐指数
1
解决办法
219
查看次数

标签 统计

c++ ×1

reference ×1