mardi 22 octobre 2019

How to make a shared pointer initialized using `initializer_list`? [duplicate]

This question already has an answer here:

If I am allowed to initialize map like this:

std::map<int, int> m(1);

Why can't I make the shared pointer the same way?

auto p = std::make_shared<std::map<int, int>>(1);

The g++ error message is:

error: too many arguments to function ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = std::map<int, int>; _Args = {}]’
   auto p = std::make_shared<std::map<int, int>>(1);
                                                         ^

Aucun commentaire:

Enregistrer un commentaire