My problem is, that I have a class which has as an object of itself. When I try to write the assignment or copy method I end in a kind of "classception"
the shortened class:
class Node
{
public:
Node(QString name, Node *parent = 0);
~Node(void);
// copy
Node(const Node &srcNode);
// assignment
Node& operator=(const Node &srcNode);
private:
QString name;
QList<Node*> children;
Node *parent;
};
and the method (just one because its almost the same)
// Copy
Node::Node(const Node &srcNode)
{
name = srcNode.name;
for(int i = 0; i < srcNode.children.size(); i++)
{
children.replace(i, srcNode.children.at(i));
}
// how is it done?
parent = srcNode.parent;
}
My problem is at the last line of the method. As you can see the parent is also an object of the type Node, so I would end up in an endless loop.
How do i deep copy this class correctly?
Hope that someone can give me a hint :)
Regards