Re: How to delete a pointer
Quote:
Originally Posted by motorizedmedia
Having a little trouble deleting a pointer, returns only jumbled up numbers...
I only see a single function that returns void.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
Regards,
Paul McKenzie
Re: How to delete a pointer
I don't know, what you are trying to achieve (your code is horribly indented and a function called deletefn that prints out a message "Could not add node to the link." does not make much sense in my mind), but deleteptr remains uninitialized throughout your function, so running delete on it might not have the desired effect.
Most compilers issue warnings in case variables are used uninitialized. Either you did not read them or you should check your compiler settings.
Re: How to delete a pointer
deleteptr.
You are effcetively doing something like the following..
Code:
Member *deleteptr;
anotherptr = deleteptr; // here deleteptr is uninitialized dangling pointer
delete deleteptr;// deleting a uninitialized pointer invoking undefined behaviour
anotherptr->SomeMethod();//calling a method on a deleted pointer which was an uninitialized pointer// Ofcourse undefined behaviour...