XmlNode’s copy constructor now recursively copies the children nodes as well

This commit is contained in:
Florent Le Coz
2014-05-30 04:00:23 +02:00
parent eb9a201870
commit 6bde78b574
2 changed files with 24 additions and 13 deletions
+7 -3
View File
@@ -35,9 +35,8 @@ public:
node.parent = nullptr;
}
/**
* The copy constructor do not copy the children or parent attributes. The
* copied node is identical to the original except that it is not attached
* to any other node.
* The copy constructor do not copy the parent attribute. The children
* nodes are all copied recursively.
*/
XmlNode(const XmlNode& node):
name(node.name),
@@ -48,6 +47,11 @@ public:
inner(node.inner),
tail(node.tail)
{
for (XmlNode* child: node.children)
{
XmlNode* child_copy = new XmlNode(*child);
this->add_child(child_copy);
}
}
~XmlNode();