以下是关于创建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)