After the delete expression, the pointer becomes invalid. According to the C++ standard access of such a pointer is implementation defined (a type of undefined behaviour). Some platforms may give you segfault, some might not. It is not true. Delete doesn't set the pointer to null.
but it's a memory safety issue, isn't it? is there a proper way to handle this case and the pointer is invalid right after using the delete expression
It is. There are two ways to go about it, 1. hide it with RAII or 2. set the pointer to null after you delete so subsequent deletes don't do anything plus your pointer is now null so trying to dereference it it will give you errors.
thank you very much. i understand the second point. i will googling what's RAII because i don't know what it is. 🙂
Обсуждают сегодня