Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A naive implementation of xml: Node extends a list of itself</p> <pre><code> class Node : public std::unordered_map&lt; std::string, std::list&lt; Node &gt; &gt; { public: Node( const std::string &amp; tag_ ) : tag( tag_ ){} void print( const std::string &amp; indent ) const { std::cout &lt;&lt; indent &lt;&lt; '&lt;' &lt;&lt; tag; if( ! attributes.empty()) { for( std::unordered_map&lt; std::string, std::string &gt;::const_iterator it2 = attributes.begin(); it2 != attributes.end(); ++it2 ) { std::cout &lt;&lt; ' ' &lt;&lt; it2-&gt;first &lt;&lt; "=\"" &lt;&lt; it2-&gt;second &lt;&lt; "\" "; } } std::cout &lt;&lt; '&gt;' &lt;&lt; std::endl; if( ! text.empty()) { std::cout &lt;&lt; indent &lt;&lt; text &lt;&lt; std::endl; } for( Node::const_iterator it1 = begin(); it1 != end(); ++it1 ) { const std::list&lt; Node &gt; &amp; lst = it1-&gt;second; for( std::list&lt; Node &gt;::const_iterator it2 = lst.begin(); it2 != lst.end(); ++it2 ) { (*it2).print( indent + '\t' ); } } std::cout &lt;&lt; indent &lt;&lt; "&lt;/" &lt;&lt; tag &lt;&lt; '&gt;' &lt;&lt; std::endl; } std::string tag; std::string text; std::unordered_map&lt; std::string, std::string &gt; attributes; }; int _tmain(int argc, _TCHAR* argv[]) { Node title( "title" ); title.text = "Title of the html page"; Node head( "head" ); head["title"].push_back( title ); Node html( "html" ); html["head"].push_back( head ); Node body( "body" ); body.attributes["bgcolor"] = "#F0F0F0"; Node p1( "p" ); p1.text = "Creativity and imagination are limitless."; body["p"].push_back( p1 ); Node p2( "p" ); p2.text = "Don't listen to the annoying guys who say your projects are dreams"; body["p"].push_back( p2 ); html["body"].push_back( body ); html.print( "" ); /* Result: &lt;html&gt; &lt;head&gt; &lt;title&gt; Title of the html page &lt;/title&gt; &lt;/head&gt; &lt;body bgcolor="#F0F0F0" &gt; &lt;p&gt; Creativity and imagination are limitless. &lt;/p&gt; &lt;p&gt; Don't listen to the annoying guys who say your projects are dreams &lt;/p&gt; &lt;/body&gt; &lt;/html&gt; */ return 0; } </code></pre> <p>Since no virtual method at all are defined, no need of virtual destructor.</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