相关疑难解决方法(0)

将std :: shared_ptr传递给构造函数

以下是关于创建Stuff和赋予它Foo所有权的合理有效的方法吗?

class Foo
{
    explicit Foo(const std::shared_ptr<Stuff>& myStuff)
        : m_myStuff(myStuff)
    {
    }

    ...

private:
    const std::shared_ptr<Stuff> m_myStuff;
}

std::shared_ptr<Stuff> foosStuff(new Stuff());
Foo f(foosStuff);
Run Code Online (Sandbox Code Playgroud)

c++ std

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

标签 统计

c++ ×1

std ×1