[Interest] C'tor member initialisation with 'this'
Frank Hemer
frank at hemer.org
Fri Jan 10 20:54:38 CET 2014
On Friday 10 January 2014 20:35:56 Jan Kundrát wrote:
> The C++'s order of destruction is, in this case:
>
> 1) ~QtSoapHttpTransport(), which does more or less nothing. By the time it
> returns, the object is no longer a QSHT (which is the reason why you must
> not call virtual methods from destructors).
>
> 2) Any member variables are destroyed. In this case, one if them is a QNAM
> which derives from QObject, so at some point the ~QObject() of the QNAM
> runs, and at that time the QNAM is removed from the list of children of its
> parent QObject, which is the former QSHT. This is safe, because
> QSHT::~QObject has not run yet, so the former QSHT is still an QObject.
>
> 3) QSHT::~QObject runs, finally. It checks the list of its children, but
> that list does not include the already destroyed QNAM, so the former QNAM
> is not deleted twice and everything is OK.
>
> Yup, took me some time to understand this as well -- thanks for an
> excellent question.
Thanks for the comprehensive explanation:-)
@Thiago: Good hint - never thought of that.
Frank
More information about the Interest
mailing list