Erreur: pas viable surcharge de l'opérateur[]

C'est un peu mon code:

#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;

    if (!doca.load_file("a.xml") || !docb.load_file("b.xml"))
        return 1;

    for (auto& node: doca.child("site_entries").children("entry")) {
        const char* id = node.child_value("id");
        mapa[new std::string(id, strlen(id))] = node;
    }

    for (auto& node: docb.child("site_entries").children("entry"))
        const char* idcs = node.child_value("id");
        std::string id = new std::string(idcs, strlen(idcs));
        if (!mapa.erase(id)) {
            mapb[id] = node;
        }
    }

Lors de la compilation, j'obtiens cette erreur:

src/main.cpp:16:13: error: no viable overloaded operator[] for type 'std::map<std::string, pugi::xml_node>'
        mapa[new std::string(id, strlen(id))] = node;
  • new std::string... --> std::string
  • Êtes-vous java homme? Parce que je pense que le langage Java ici: std::string id = new std::string(idcs, strlen(idcs)); . Vous n'avez pas new locales les variables en C++.
  • De nos jours, vous n'avez pas new rien en C++.
InformationsquelleAutor Jimmy | 2015-04-17