Is it worth setting pointers to NULL in a destructor?
- by Rob
Imagine I have a class that allocates memory (forget about smart pointers for now):
class Foo
{
public:
Foo() : bar(new Bar)
{
}
~Foo()
{
delete bar;
}
void doSomething()
{
bar->doSomething();
}
private:
Bar* bar;
};
As well as deleting the objects in the destructor is it also worth setting them to NULL?
I'm assuming that setting the pointer to NULL in the destructor of the example above is a waste of time.