use*_*836 3 c++ return function shared-ptr
当我尝试从我得到的函数返回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的正确方法是什么?