Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMarkS

Posted 15 October 2012 - 12:46 PM

Explicitly calling the destructor does not do what you think it does. In particular, calling the destructor of an object from within its constructor will not affect the members of the class, and you will still leak just as bad as before.


Interesting! OK, time to stop using C-style pointers...

BTW, what is this "safe delete" thing?


It comes from a book, "Teach yourself C++ in 24 hours." I don't remember the exact reason and no longer have the book, but something about calling delete on a NULL pointer is safe, but calling it on an uninitialized pointer can lead to problems. The book mentioned setting the pointer to NULL after delete in the event that delete is called twice (why this would happen, I do not know...). I have always done this.

#2MarkS

Posted 15 October 2012 - 12:45 PM

Explicitly calling the destructor does not do what you think it does. In particular, calling the destructor of an object from within its constructor will not affect the members of the class, and you will still leak just as bad as before.


Interesting! OK, time to stop using C-style pointers...

BTW, what is this "safe delete" thing?


It comes from a book, "Teach yourself C++ in 24 hours." I don't remember the exact reason and no longer have the book, but something about calling delete on a NULL pointer is safe, but calling it on an uninitialized pointer can lead to problems. The book mentioned setting the pointer to NULL after delete in the even that delete is called twice. I have always done this.

#1MarkS

Posted 15 October 2012 - 12:42 PM

Explicitly calling the destructor does not do what you think it does. In particular, calling the destructor of an object from within its constructor will not affect the members of the class, and you will still leak just as bad as before.


Interesting! OK, time to stop using C-style pointers...

PARTNERS