Hello!
I study about linked stacks. I practice at a basic example.
I have the following part of the code
Error_code is typedef
Node is a struct
1 2 3 4 5 6 7 8 9 10 11
|
Error_code Stack::pop()
{
if (empty()) return underflow;
Node *old_top = top_node;
top_node = top_node->next;
delete old_top;
return success;
}
|
My question here is about
delete old_top;
Here it deletes the data member of the struct, right ?
Also about pointers i can only delete pointer when is dynamic(i use new) and not static, right ?
Thanks for the help!
Last edited on
It deletes what the pointer is pointing to, so if what top_node was pointing to before line 5 was allocated with new, it is OK.
As for the question, yes, you only delete things that have been new
'd.