Re: Arbitrary number of child windows



> I am however a bit sceptic
> on the frequent use of "delete this;" in member functions. As far as I
> know, "delete this;" itself is valid, but any other statement, even a
> return statement, is undefined behaviour. I might be wrong about that
> though.

Yes, you are wrong.  Provided that no members of the object in question
are operated on after 'delete this', then it is fine.  A return
statement is entirely unproblematic.

Calling 'delete this' does not often represent the correct approach, but
one notable exception is objects which are self owning and control their
own lifetime by reference to user input.  Non-modal (non-blocking)
dialogs are an example of a such a type of object.

Handing it off to some other handler, such as an idle handler, does
exactly the same as 'delete this' but at some indeterminate time later.
It is better to do it directly and call 'delete this'.

Make sure that the destructor is virtual though.

Chris




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]