2 File IO Questions (Phobos)

Frank Benoit keinfarbton at googlemail.com
Sat Nov 7 03:51:18 PST 2009


Zane schrieb:
> Doh! I still need help with number 2, but for number 1, all I needed
> was to use 'writeString' instead of 'write'.  Like I said, still
> getting used to Phobos.  Like I said, I still need help on the
> destructor question (#2).
> 
> Thanks, Zane

desctructors are called in not defined order. The GC puts your class
instance 'sw' and the File instance 'sw.file' onto the list for
destruction. So the 'sw.file' might be destructed before 'sw' is.
Deferencing sw.file from withing sw.~this then fails.

A general rule: in a dtor, never dereference member variables.

You have to rely on the File dtor, to close himself if still open.


More information about the Digitalmars-d-learn mailing list