Why no acess to other structs in classes?

Bill Baxter wbaxter at gmail.com
Sun Nov 5 09:47:38 PST 2006


John Demme wrote:
> Karen Lanrap wrote:
> 
> 
>>class C
>>{
>>    struct S
>>    {
>>        uint data;
>>    }
>>    S s;
>>    struct T
>>    {
>>        uint f()
>>        {
>>            return s.data;
>>            // this for s needs to be type C not type T *
>>        }
>>    }
>>}
>>void main(){}
> 
> 
> 
> Actually, it's more generic than that- the inner struct can't access any
> member variable of the outer class:
> 
> class C
> {
>     uint s;
>     struct T
>     {
>         uint f()
>         {
>             return s;
>             // this for s needs to be type C not type T *
>         }
>     }
> }
> 
> void main(){}
> 
> I'm not certain if this is a bug or if there is a good reason for this.
> 

Odd.  I could have sworn I saw there was a .outer property added in a 
recent version.  Apparently it only applies to inner classes, not 
structs.  This compiles:

class C
{
     uint s;
     class T
     {
         uint f()
         {
             return this.outer.s;
         }
     }
}

void main(){}


--bb



More information about the Digitalmars-d-learn mailing list