Can't create nested classes
Bradley Smith
digitalmars-com at baysmith.com
Tue Jan 23 13:40:25 PST 2007
The crash in the example code isn't from nested classes. It is from the
destructor of class Writer. The destructor is calling a method on the
garbage collected member object "testFile". This reference is no longer
valid.
From http://www.digitalmars.com/d/class.html#destructors
"When the garbage collector calls a destructor for an object of a class
that has members that are references to garbage collected objects, those
references are no longer valid."
In addition, the call is unnecessary because the class File will call
close() in its destructor.
Heinz wrote:
> Alexander Panek Wrote:
>
>> Heinz wrote:
>>> I can't also have variables like 'int i', it throws access violation. But why in the DMD page here http://www.digitalmars.com/d/class.html is listed a bunch of classes with 1 to 3 non-static members like int i?
>>>
>>> Man, C# is a lot more flexible in this topic, why can we have non-static members in C# and not in D?
>> No offense intended, but I do think you're doing something wrong here.
>> Would you mind pasting the whole source code, please?
>
>
> Sure man, attached is the code with the main file included, just compile with these 2 files and you're ready.
>
> I noticed if i remove all references to type File or delegate, it works ok. I mean, you can have the delegate or the File but not both.
>
> Good luck
More information about the Digitalmars-d-learn
mailing list