lundi 20 juillet 2015

How to initialize a shared pointer in the initialization list of a constructor?

How can I initialize a shared pointer in the initialization list of a constructor?

I have this:

Foo::Foo (const callback &cb)
{
    Bar bar;
    bar.m_callback = cb;
    m_ptr = std::make_shared<Bar>(bar);

    //...
}

I would like to put this into the initializer list of the contructor. Something like:

Foo::Foo (const callback &cb) :
   m_ptr(std::make_shared<Bar>(?????))
{
  // ...
}

Aucun commentaire:

Enregistrer un commentaire