当我尝试从我得到的函数返回shared_ptr时:返回对本地变量'recipe'的引用[-Werror = return-local-addr]
我哪里做错了 ?
shared_ptr<Recipe>& Group::addRecipe(const string& groupName, unsigned int autherId, const string& recipeName){
shared_ptr<Recipe> recipe(new Recipe(recipeName, autherId));
recipes.push_back(recipe);
return recipe;
}
Run Code Online (Sandbox Code Playgroud)
返回shared_ptr的正确方法是什么?
我是整体编程的新手.
我已经尝试阅读该语言的官方标准,但无法找到我的问题的任何答案.
所以我需要了解在C++中void类型和其他不完整类型之间的主要区别.例如:语言(或代码)中是否存在我们可以使用void而不是其他不完整类型的位置,反之亦然?或者像其他各种不完整类型一样无效?