//the copy constructor. Make sure this performs deep copy!!!!
IntList::IntList(const IntList& cpy){
IntNode* tmp = new IntNode;
head = 0;
tail = 0;
for(IntNode* i = cpy.head; i != 0; i = i->next){
push_back(i->data);
}
}
these are error message
*** Error in `./a.out': double free or corruption (fasttop): 0x0000000001fd3280 ***
Test feedback
Passed empty list test
Passed single node test
Passed 2+ node test
and below is overloaded operator
IntList& IntList::operator=(const IntList& rhs){
while(head != 0){
IntNode *tmp = head;
head = head -> next;
delete tmp;
}
tail = head;
for(IntNode* i = rhs.head; i != 0; i = i -> next){
push_back(i->data);
}
return *this;
}
this is error message for overloaded operator
*** Error in `./a.out': double free or corruption (fasttop): 0x0000000001c4b280 ***
Test feedback
Copy constructor did not work with self-assignment (i.e., list1 = list1).
Expected IntList: -1 40 136 144 -100 121 101 42 -23 -31 199
Actual IntList:
these are my copy constructor, and overloaded assignment operator.
I understand the concept of deep copy, but i'm confused to implement.
Can anyone help?
and my push_back is this
void IntList::push_back(int value){
if(empty() == true){
head = tail = new IntNode(value);
head ->next = tail;
}
else if(empty() == false){
IntNode* tmp = new IntNode(value);
tail->next = tmp;
tmp->next = 0;
tail = tmp;
}
}