Inner classes - More expressiveness needed

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Oct 25 06:23:13 PDT 2007


"Janice Caron" <caron800 at googlemail.com> wrote in message 
news:mailman.508.1193317715.16939.digitalmars-d at puremagic.com...
>I can't call this a bug, because I think it's behaving as documented.
> Nonetheless, it seems to be that D could be more expressive. The
> following won't compile:
>
>    class Outer
>    {
>        int n;
>
>        class Inner
>        {
>            static int f() { return n; }
>        }
>    }
>
> The error is:
> Error: need 'this' to access member n
>
> The problem is that the word "static" is horribly overused, and
> doubles up to mean BOTH "the function does not have a this pointer"
> AND "this function does not have an outer pointer".
>
> There seems no way to express "please can my function have an outer
> pointer but not a this pointer" (which is what I was trying to
> achieve).
>
> There also seems no way to express "please can my function have a this
> pointer but not an outer pointer". (I wasn't trying to achieve that,
> but it could conceivably be useful).
>
> I wonder if we might find some way of expressing those ideas?

I have no idea how that'd be implemented.  The thing is that the 'outer' is 
not contained somewhere special; it's just a hidden member of every instance 
of the inner class.  When you access outer members, you're really doing 
this.outer.member.  For a static inner function, however, there's no way to 
associate an "instance of the function" (which doesn't really mean much) 
with an instance of Outer.

Furthermore there are (please don't hit me) static inner classes, which do 
not have an outer pointer.  Again, the outer pointer is per-instance, so 
this just involves not putting an outer pointer in the instance. 





More information about the Digitalmars-d mailing list