EDIT - *slaps forehead*
A copy constructor is not the same as overloading the = sign...is it?
/END EDIT
I'm currently coding a program that lets me calculate 2 very large integer values using linked lists. At the moment, I'm just making sure that the numbers are stored properly before overloading any operators.
The problem is, I created a Temp variable and made it equal to the first number, but when the program exits and deletes the linked lists, the verbose data shown in the destructor for the Temp var is basically garbage. Especially in a situation where I enter number with more than 3 digits, in which it enters an infinite loop where it "deletes" a pointer containing the same value.
It seems that when it deletes the linked list containing the first number, the Temp variable gets affected. This is is strange since that implies that the Temp node pointers are sharing addresses with the first number. So with this in mind, I've concluded that it is an issue with my copy constructor, but I fail to see how it is sharing memory with the item it is copying.
Code:
Number::Number(const Number &ListToCopy)
{ //seems to share memory locations with listtocopy and this causes big issues when deleting
IntNodePtr Temp = ListToCopy.Head;
headInsert(Head, Temp->getData()); //copies data from first node and creates a copy node
for (IntNodePtr Temp = ListToCopy.Head; Temp != NULL; Temp = Temp->getLink())
{
Temp = Temp->getLink();
insert(Head, Temp->getData()); //should create a new node with copied data
}
Negative = ListToCopy.Negative;
}
Any help would be appreciated.