Angry citizen stikes once again. forward references problems

Unknown W. Brackets unknown at simplemachines.org
Sun Jul 30 15:59:54 PDT 2006


Your example is incorrect.  It should be:

class X
{
    static class NX
    {
    }
}

class Y
{
    X.NX q;
}

Which compiles, indeed.

That said, I don't use a lot of cycles as far as nested classes... 
honestly it feels weird to me (as you said.)

So can't... actually you can.  Shouldn't... hmm, yeah.  Gotta love 
conventions, some are good, some are weird.

-[Unknown]


> On Sun, 30 Jul 2006 21:55:59 +0200, Dawid Ciężarkiewicz wrote:
> 
>> Dawid Ciężarkiewicz wrote:
>>> In extremal situations you can even get something you can't compile in any
>>> way:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=104
>> I mean:
>> http://d.puremagic.com/issues/show_bug.cgi?id=102
> 
> I don't understand this Dawid. It seems you are trying to use a nested
> class inside another class, and I'm sure you can't and shouldn't do that.
> 
> I thought the purpose of nested classes was to restrict the scope of the
> nested class to its parent and thus trying to use it outside of the parent
> doesn't seem right to me.
> 
> Your example..
> //  --- test2.d -----
> import test2;
> class X
> {
>   Y.NY t;  // ?!? But NY is defined as a nested class in Y.
>   static class NX
>   {
>   }
> }
> //-------------------------//
> 
> 
> //  --- test.d -----
> import test;
> class Y
> {
>   X.NX nx;  // ?!? But NX is defined as a nested class in X.
>   static class NY
>   {
>   }
> }
> //-------------------------//
> 
> 
> D won't let you do even the more simple case ...
> 
> //------- test3.d -----
> class X
> {
>   static class NX
>   {
>   }
> }
> 
> class Y
> {
>      NX q; // test3.d(10): identifier 'NX' is not defined
> }
> // -------------------- //
> 
> I think dmd is working correctly, though the error messages are not exactly
> helpful.
> 



More information about the Digitalmars-d mailing list