Possible Duplicate:
Is it worth setting pointers to NULL in a destructor?
Do I have to do something like so:
~MyClass()
{
delete[] my_data_;
my_data_ = nullptr;//DO I HAVE TO WRITE THIS LINE?
}
Thank you.
Possible Duplicate:
Is it worth setting pointers to NULL in a destructor?
Do I have to do something like so:
~MyClass()
{
delete[] my_data_;
my_data_ = nullptr;//DO I HAVE TO WRITE THIS LINE?
}
Thank you.
No. Once the destructor has completed, there's no way of legally accessing that pointer, so it doesn't matter what its final value is.
delete[] my_data_;
Should do all you need, after you use this then setting my_data_ to nullptr is not necessary.
No, it only clutters code, has no real use and can be even optimized away by the compiler. Anyway once the destructor returns the object lifetime ends and there're no legal ways to access it - trying to would result in undefined behavior anyway.