"Joanna Carter" <✉no.spam.for.me> wrote in message news:✉forums.codegear.com...
> Loren Pechtel a __crit : > >> tFoo still can. The dead instance of tFoo can still be referenced.
Exactly. And anybody having a reference can call methods on that reference that access the inner object.
> TFoo is a classnot an instance. Unless you still have a reference to an > instance of TFoo, then you can't access the dead instance.
Finally...
> And, if your code calls the destructor on anything other than the last > reference left alive, then you have a logic error.
It is not just about calling the destructor ... Any method on a dead instance can be called and any method can (and is allowed) access the private inner instances.
> Good programmers know to only create and destroy within the same scope. > Any other references to the same object have absolutely no right to call > the destructor. It's a question of ownership - there should only ever be > one owner of any instance - all other references are non-owning and must > not destroy it.
I prefer not to rely on rules alone. People are fallible, including me. I therefore prefer to employ runtime strategies as well that help me find infringements of the rules as immediately as possible. -- Marjan Venema