Hi, quick question.
What happens to memory that is allocated in a fashion such as this- Item* temp = new Item ///Item is a struct
when its pointer is reassigned in a manner like this?
1 2 3 4
Item* temp = new Item ///Item is a struct
Item* temp2 = new Item;
temp = temp2;
When it is reassigned to another "new" allocated memory, does it become an unpointed to memory leak? Or does it free itself since its not being pointed to?
I've learned this answer in my studies, but I've forgotten and I can't seem to google the correct phrase question.
Thanks.
Head is the latest item in the linked list. Would using an automatic pointer variable like this work?
Pointing it to the address I wish close and then having it automatically delete when the function ends?
;) Yes. calling new in remove() does not make too much sense, hm? But check if temp actually points to an object (don't forget to initialize an empty pointer to null)