dimanche 19 avril 2015

Member is not a structure or union

When I compile this demo code I was told I had an error where I didn't define n. Now I tried to define n as an int but it tells me this error. I also had the same problem with using char. Is this meant to be a string instead and if so how do I define it?



src/main.cpp:22:32: error: member reference base type 'char' is not a structure or union
auto found = tagmaps.find(n.name());
~^~~~~
src/main.cpp:49:24: error: member reference base type 'char' is not a structure or union
found = tagmaps.find(n.name());
~^~~~~


This is my full code:



#include "pugi/pugixml.hpp"

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

int main()
{

// Define mappings, default left - map on the right
const std::map<std::string, std::string> tagmaps
{
{"id", "id"}
, {"description", "content"}
}
int n;
pugi::xml_document doca, docb;
auto found = tagmaps.find(n.name());
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 (auto& ea: mapa) {
std::cout << "Removed:" << std::endl;
ea.second.print(std::cout);
}

for (auto& eb: mapb) {
// change node name if mapping found
found = tagmaps.find(n.name());
if((found != tagmaps.end()) {
n.set_name(found->second.c_str());
}
}


EDIT: This code is meant to check if any of the node names match what is defined in the map, i.e it would look for any nodes called id and content


Aucun commentaire:

Enregistrer un commentaire