c++ - Missing constructor for initialization for map -


i had on previous topic, had change map use int in combination strings. when have done gives me different issue. issue:

src/main.cpp:11:29: error: no matching constructor initialization of       'std::map<int, std::string>'   ...tagmap {{"1", "data"}, {"2", "entry"}, {"3", "id"}, {"4", "content"}};      ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

it seems issue (which looked on topic) seems allude fact issue making constructor take const references? don't understand how implement this.

#include "pugi/pugixml.hpp"  #include <iostream> #include <string> #include <map>  int main() {     pugi::xml_document doca, docb;     std::map<std::string, pugi::xml_node> mapa, mapb;     std::map<int, std::string> tagmap {{"1", "data"}, {"2", "entry"}, {"3", "id"}, {"4", "content"}};      if (!doca.load_file("a.xml") || !docb.load_file("b.xml")) {         std::cout << "can't find input files";         return 1;     }      (auto& node: doca.child(tagmap[1]).children(tagmap[2])) {         const char* id = node.child_value(tagmap[3]);         mapa[id] = node;     }      (auto& node: docb.child(tagmap[1]).children(tagmap[2])) {         const char* idcs = node.child_value(tagmap[3]);         if (!mapa.erase(idcs)) {             mapb[idcs] = node;         }     } } 

any appreciated.

try sth like:

#include <iostream> #include <map> #include <string>  using namespace std;  int main() {    std::map<int, std::string> tagmap {make_pair(1, "data"), make_pair(2, "entry")}; } 

edit: version without make_pair function valid:

#include <iostream> #include <map> #include <string>  using namespace std;  int main() {    std::map<int, std::string> tagmap {{1, "data"}, {2, "entry"}}; } 

the thing need remember shouldn't rely on compiler const string literal number cast...


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -