I have an error in my project and I can't fix the problem
#pragma once
class Node
{
int code;
int count;
Node* parent;
Node* rightChild;
Node* leftChild;
public:
Node(int c1,int c2);
void setCode(int c);
void setCounter(int c);
void setRightChild(Node n);
void setleftChild(Node n);
void setParent(Node n);
int getCode();
int getCounter();
Node getRightChild();
Node getleftChild();
Node getParent();
Node(void);
~Node(void);
};
#include "Node.h"
Node::Node(void)
{
}
Node::~Node(void)
{
//delete this;
}
Node::Node(int c1, int c2){
code=c1;
count=c2;
parent=0;
rightChild=0;
leftChild=0;
}
int Node::getCounter()
{
return count;
}
Node Node::getleftChild()
{
return(*leftChild);
}
Node Node::getRightChild()
{
return (*rightChild);
}
Node Node::getParent()
{
return (*parent);
}
void Node::setCode(int c)
{
code=c;
}
void Node::setCounter(int c)
{
count=c;
}
void Node::setleftChild(Node n1)
{
leftChild=&n1;
}
void Node::setRightChild(Node n2)
{
rightChild=&n2;
}
void Node::setParent(Node n)
{
parent=&n;
}
int Node::getCode(){
return code;
}
#include"Elem.h"
using namespace std;
int main(){
//Node n2(3,4);
Node n3(5,6);
Node n4(7,8);
Node n5(9,10);
n3.setRightChild(n4);
n3.setleftChild(n5);
return 0;
}
my problem is when I setrightchild of n3.(with debug it's changed)
but when I setleftchild (with debug the rightleftchild also changes and the left also changes to the same numbers
I need any help in this previuose
any help will be accepted.