Fehler: keine brauchbare überladenen operator[]

Das ist ein bisschen mein 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;
        }
    }

Beim kompilieren bekomme ich diesen Fehler:

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
  • Sind Sie auf der java-Mensch? Weil ich das Gefühl Java hier: std::string id = new std::string(idcs, strlen(idcs)); . Sie nicht new lokale Variablen in C++.
  • Heute, Sie nicht new alles in C++.
InformationsquelleAutor Jimmy | 2015-04-17
Schreibe einen Kommentar