On Tue, 10 Aug 2010 09:21:30 -0400, Andrej Mitrovic <[email protected]> wrote:

I see. I agree clear() is definitely safer in these situations. But if the constructor gets called again automatically after clear(), that would mean the other references could still use the object since it's in a valid state
again, right?

Not really. Who defines 'valid state'? You might expect it to still contain the data you put in it through some member function. An object goes through many states while alive, and arbitrarily picking one of those states and declaring it 'valid' is simply bad practice. Better to pick a reasonable state that *all* objects can be set to, and call it invalid.

When you clear an object, you are saying "I no longer need this data from here or anywhere else" Any access to that object after calling clear is a program error. All clear does vs. delete is make it so an invalid access to that data doesn't cause your program to explode in unpredictable ways.

-Steve

Reply via email to