On 2002-06-06, Christoph Bugel wrote:
> On 2002-06-06, Nadav Har'El wrote:
> > On Thu, Jun 06, 2002, Christoph Bugel wrote about "Re: Some C++ Questions":
> > > > And never do something like "delete this"!
> > > 
> > > I guess "never" is not the correct word.
> > > There *are* legitimate uses of "delete this",
> > > For example in the RCProxy design pattern.
> > 
> > I'm not a design-patterns expert, so maybe I'm missing something, but
> > how can you do "delete this" from within an object? First, I don't see
> > how you know that this object was dynamically-allocated (it might have
> > been on the stack, allocated as part of an array of objects, allocated
> > with placement-new, etc.).
> > 
> > Second, what happens after the "delete this"? The method continues to
> > run but the object was destructed; If you do anything except "return"
> > after the "delete this" you might accidentally try to use members of
> > the deleted object...
> 
> I'm by no means a design patterns expert either :-)
> 
> But I'll try to explain the Reference-Counted Proxy pattern, as I
> understand it: There is a class that is for the user (the proxy class)
[...]

I forgot to actually answer your questions :)

The points that you raise are both valid, and it is the programmers
responsibility to protect against them. in the example I showed they are
both taken care of by the programmer of the String 'class library'.
(The *user* of that class library doesn't have to worry about those
dangers!)
(1) the delete this statement is not followed by any other statement
(2) the StringImp object is always created by e 'new' statement: heap.

The user should/can only use the String class, so there is no way the
StringImp will be created on the stack. This can even be enforced, by
makeing the StringImp constructor can be made private)




=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to