R
Rolf Magnus
Victor said:Possibly not. We're talking "from a technical point of view".
That's what _you_ are talking about. The question was: "However, what does
the C++ standard say?"
Victor said:Possibly not. We're talking "from a technical point of view".
Rolf said:That's what _you_ are talking about. The question was: "However, what
does the C++ standard say?"
Victor said:Yes, Rolf. And I answered it already: "nothing special".
Anything else you need to clarify?
James said:[..]
In practice, if "delete this" weren't the last thing you do in
the function (except maybe some logging), I'd be very unhappy.
(In a similar way, I don't like deleting an arbitrary pointer
except when the pointer is immediately going out of scope.)
James said:[..]
In practice, if "delete this" weren't the last thing you do in
the function (except maybe some logging), I'd be very unhappy.
Whatever is done after that should be very well documented to
[try to] prevent somebody from adding something with undefined
behaviour to it.
That's not always practical. What is better by far is setting
the deleted pointer to 0 right after deletion.
James said:James said:[..]
In practice, if "delete this" weren't the last thing you do in
the function (except maybe some logging), I'd be very unhappy.Whatever is done after that should be very well documented to
[try to] prevent somebody from adding something with undefined
behaviour to it.
The presence of "delete this" in the code should be
documentation enough. In functions which call this function,
too: hopefully, no one is doing maintenance on the code without
knowing what the function he is modifying is supposed to do.
That's not always practical. What is better by far is setting
the deleted pointer to 0 right after deletion.
That's typically wasted effort, since the actual pointer is
immediately going out of scope.
The problem (whether "delete
this" or "delete p") is always the other pointers to the object.
James said:James Kanze wrote:
[..]
In practice, if "delete this" weren't the last thing you do in
the function (except maybe some logging), I'd be very unhappy.Whatever is done after that should be very well documented to
[try to] prevent somebody from adding something with undefined
behaviour to it.
The presence of "delete this" in the code should be
documentation enough. In functions which call this function,
too: hopefully, no one is doing maintenance on the code without
knowing what the function he is modifying is supposed to do.
(In a similar way, I don't like deleting an arbitrary pointer
except when the pointer is immediately going out of scope.)That's not always practical. What is better by far is setting
the deleted pointer to 0 right after deletion.
That's typically wasted effort, since the actual pointer is
immediately going out of scope.
Uh.. no. If my object contains a pointer to a dynamically allocated
object, and my object is going to survive much longer than the object
it allocated, it makes all the sense in the world to keep the pointer
null until next allocation is made. Think list, tree, any other
hierarchical dynamic structure.
We've gone off the original subject a bit here, though.
The problem (whether "delete
this" or "delete p") is always the other pointers to the object.
Not sure what you mean.
Greg said:The problem is that it is often "hard" to chase exactly which
additional pointers "should" be zero'd although with the "obvious
one." This is not the same as using an invalid pointer later on,
because, among other reasons, it may not be hard to not use it at
other points in the life of the program.
Note: This is a very debatable conversation. I've never been
in one on this topic which everybody got swayed one way or the other,
although it led to some converts.
Yes, I realise that setting a single pointer to null does not make
other copies of the same pointer null as well. If that's the point,
I get it. That's why I said that setting 'this' to null is not
viable but it would be nice if it were possible.
Are you calling "delete this" debatable or setting the pointer to
null debatable? I am not challenging either point of view, I am
just trying to clarify.
The presence of "delete this" in the code should be
documentation enough.
Uh.. no. If my object contains a pointer to a dynamically allocated
object, and my object is going to survive much longer than the object
it allocated, it makes all the sense in the world to keep the pointer
null until next allocation is made.
Think list, tree, any other hierarchical dynamic structure.
We've gone off the original subject a bit here, though.
Not sure what you mean.
Dnia Fri, 06 Apr 2007 01:45:22 -0700, James Kanze napisa³(a):
Only if you have access to this code and can read it
If you've got only compiled module with *.h, you're in ass ;P
My 2 cents: it's possible to call 'delete this', but it's
a hidden nasty little bastard who might bite you the whole leg:
It's possible to keep track the code inside a method which
calls 'delete this', but the outer code could possibly even
not know if the pointer used to call that nasty method is
still valid.
If the method call 'delete this' inside, the
valid pointer turns to invalid discretely.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.