Funtion return Error

Value store in 'first' suddenly changed, when 'return' statement execeuted and return Garbage Value.

char *List:: removeFirstNumber()
{
Node *temp,*p;
char *first;
temp=p=head;
first=head->getData();
temp=temp->getNext();
head=temp;
delete p;
return first;
}

Plz Help me ! How could i solve this problem ?? :(
Last edited on
1
2
3
4
5
p=head;
//...
first=head->getData();
//...
delete p;

You are trying to access deleted data.
This will lead to undefined behavior.
Topic archived. No new replies allowed.