Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to understand RapidXml memory allocation
    text
    copied!<p>I'm using RapidXml in a c++ program. Well ok no problem it works. I just do not understand why I must use pointers instead of variable values... If you take a look to the RapidXml wiki page, some examples are provided, this is the one provided by RapidXml developers:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include "rapidxml-1.13/rapidxml.hpp" #include "rapidxml-1.13/rapidxml_print.hpp" int main(int argc, char** argv); int main(int argc, char** argv) { using namespace rapidxml; xml_document&lt;&gt; doc; // xml declaration xml_node&lt;&gt;* decl = doc.allocate_node(node_declaration); decl-&gt;append_attribute(doc.allocate_attribute("version", "1.0")); decl-&gt;append_attribute(doc.allocate_attribute("encoding", "utf-8")); doc.append_node(decl); // root node xml_node&lt;&gt;* root = doc.allocate_node(node_element, "rootnode"); root-&gt;append_attribute(doc.allocate_attribute("version", "1.0")); root-&gt;append_attribute(doc.allocate_attribute("type", "example")); doc.append_node(root); // child node xml_node&lt;&gt;* child = doc.allocate_node(node_element, "childnode"); root-&gt;append_node(child); xml_node&lt;&gt;* child2 = doc.allocate_node(node_element, "childnode"); root-&gt;append_node(child2); std::string xml_as_string; // watch for name collisions here, print() is a very common function name! print(std::back_inserter(xml_as_string), doc); std::cout &lt;&lt; xml_as_string &lt;&lt; std::endl; // xml_as_string now contains the XML in string form, indented // (in all its angle bracket glory) std::string xml_no_indent; // print_no_indenting is the only flag that print() knows about print(std::back_inserter(xml_no_indent), doc, print_no_indenting); // xml_no_indent now contains non-indented XML std::cout &lt;&lt; xml_no_indent &lt;&lt; std::endl; } </code></pre> <p>Well, why does it use a pointer to xml_node???</p> <p>I ask this because I need to a function to return a xml_node...</p> <p>So if I do this:</p> <p>xml_node&lt;>* mynode = ... return *mynode;</p> <p>is it ok?? Because I want to use the returned node and all its children later. Is it good to do in this way? If not, how should I do?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload