samedi 30 novembre 2019

Initialization of map with a list as value

I am trying to initialize a map that contains a list

map<string, list<int>> firstNamesMap = name1;

I get the following error:

error: could not convert ‘name1’ from ‘<brace-enclosed initializer list>’ to ‘std::map<std::basic_string<char>, std::list<int> >’
 map<string, list<int>> firstNamesMap = name1;
                                                                 ^

I was originally trying to initialize a much larger map with list<Data *> instead of list<int>, in which "Data" is a simple class declared earlier. It produces the same error either way though.

Not sure if it matters, but I'm compiling with g++ in Cygwin.

Aucun commentaire:

Enregistrer un commentaire