There is no suitable member function to call child.value

When I try to compile the code below, I get an error message:

src/main.cpp:51:48: error: no matching member function for call to 'child_value'
                        std::cout << "which has value" << eb.second.child_value(kv.second);
                                                      ~~~~~~~~~~^~~~~~~~~~~

What I do not understand, I was able to use this in the loop above. I can only assume that he wants me to use kv.second.child_value(kv.second);instead. However, I want it to run this code in the xml returned for (auto& eb: mapb) {.

#include "pugi/pugixml.hpp"

#include <iostream>
#include <string>
#include <map>

int main()
{

    const std::map<std::string, std::string> tagMap {
        {"description", "content"}, {"url", "web_address"}
    };

    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")) { 
        std::cout << "Can't find input files";
        return 1;
    }

    for (auto& node: doca.child("data").children("entry")) {
    const char* id = node.child_value("id");
    mapa[id] = node;
    }

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

    // For removed
    for (auto& ea: mapa) {
    std::cout << "Removed:" << std::endl;
    ea.second.print(std::cout);
    }

    // For added nodes
    for (auto& eb: mapb) {
        // Loop through tag map
        for (auto& kv : tagMap) {
            // Try to find the tag name named in second map value
            // and associate it to the type of information in first map value
            std::cout << "Found" << kv.first;
            std::cout << "which has value" << eb.second.child_value(kv.second);
        }
    }

}

If anyone could explain what I am doing wrong, I would really appreciate it.

+4
source share
1 answer

According to two overloads found here

// Get child value of current node; that is, value of the first child node of type PCDATA/CDATA
const char_t* child_value() const;

// Get child value of child with specified name. Equivalent to child(name).child_value().
const char_t* child_value(const char_t* name) const;

you need to pass a pointer to a string (or string literal).

std::cout << "which has value" << eb.second.child_value(kv.second.c_str());
                                                        ^^^^^^^^^^^^^^^^^
+5
source

All Articles