E
exergy
Hello, if I have a class like this:
class Node{
private:
int x;
Node* parent;
public:
Node(const Node& N)
{
......
}
Node& operator =(const Node& n)
{
......
}
~Node()
{
.....
}
// other member functions
}
How do I make a copy of private field Node* parent itself? I read some
references online, some use "new" operator to allocate dynamic memory,
so what I did was
Node(const Node& p)
{
x=p.x;
Node temp=*(p.parent)
parent=new node(temp);
}
However, x value was copied, not the parent pointer.
anyone can help?
class Node{
private:
int x;
Node* parent;
public:
Node(const Node& N)
{
......
}
Node& operator =(const Node& n)
{
......
}
~Node()
{
.....
}
// other member functions
}
How do I make a copy of private field Node* parent itself? I read some
references online, some use "new" operator to allocate dynamic memory,
so what I did was
Node(const Node& p)
{
x=p.x;
Node temp=*(p.parent)
parent=new node(temp);
}
However, x value was copied, not the parent pointer.
anyone can help?