小编use*_*836的帖子

c ++:如何从函数返回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的正确方法是什么?

c++ return function shared-ptr

3
推荐指数
1
解决办法
1961
查看次数

在C++中,void和其他不完整类型之间的主要区别是什么?

我是整体编程的新手.

我已经尝试阅读该语言的官方标准,但无法找到我的问题的任何答案.

所以我需要了解在C++中void类型和其他不完整类型之间的主要区别.例如:语言(或代码)中是否存在我们可以使用void而不是其他不完整类型的位置,反之亦然?或者像其他各种不完整类型一样无效?

c++ types void incomplete-type

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

标签 统计

c++ ×2

function ×1

incomplete-type ×1

return ×1

shared-ptr ×1

types ×1

void ×1