TDPL: Manual invocation of destructor
Steven Schveighoffer
schveiguy at yahoo.com
Tue Aug 10 05:11:39 PDT 2010
On Mon, 09 Aug 2010 20:53:16 -0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Jonathan M Davis wrote:
>> On Monday, August 09, 2010 16:40:23 Andrei Alexandrescu wrote:
>>> class File {
>>> FILE * fp;
>>> this() { fp = fopen("/tmp/temporary"); }
>>> ~this() { fclose(fp); }
>>> }
>>>
>>> The destructor does not test fp because it assumes it was opened.
>>>
>>> Interestingly enough, by TDPL the code above is in fact invalid
>>> already.
>>> TDPL mentions that an object's lifetime starts as soon as it's been
>>> branded, which is before default construction. As a direct consequence,
>>> the destructor should be able to deal with an object stamped with all
>>> init values for all fields - in this case a null fp.
>> I would take that as an argument for making clear() set the object in
>> the state prior to the constructor call.
> [snip]
>
> I agree. Do others?
Yes, this is exactly what I was saying.
-Steve
More information about the Digitalmars-d
mailing list