In this answer to this question, it was noted that:
If you’re going to ‘clear’ the pointer in the dtor, a different idiom would be better – set the pointer to a known bad pointer value.
and also that the destructor should be:
~Foo()
{
delete bar;
if (DEBUG) bar = (bar_type*)(long_ptr)(0xDEADBEEF);
}
I got two question about these parts of the answer.
Fristly, how can you set the pointer to a known bad pointer value? How can you set a pointer to an address which you can assure won’t be allocated?
Secondly, what does: if (DEBUG) bar = (bar_type*)(long_ptr)(0xDEADBEEF);
even do? What’s DEBUG ? I couldn’t find a macro named so. Also, what’s long_ptr? what does it do?
Thanks.