vendredi 27 septembre 2019

Initializing std::shared_ptr with std::make_shared having an std::array as argument

I do not understand why this works fine:

std::array<double, 2> somearray = {0,1};
std::shared_ptr<MyClass> myobj = make_shared<MyClass>(somearray);

But this does not work:

std::shared_ptr<MyClass> myobj = make_shared<MyClass>({0,1});

It says:

too many arguments to function ‘std::shared_ptr< _Tp> std::make_shared(_Args&& ...)
...
candidate expects 1 argument, 0 provided

Can someone clarify why this happens and if there is any way I can fix the second approach without defining an extra variable?

Aucun commentaire:

Enregistrer un commentaire