inner member classes in final outer class

coxalan coxalan at web.de
Sun Sep 16 08:27:21 PDT 2007


Bruno Medeiros Wrote:

> I was thinking the following:
> 
>    class Outer {
>    }
> 
>    class Inner(alias outer) {
>      static assert(is(outer : Outer)); // Just a check
>    }
> 
>    final Outer o1 = new Outer();
>    final Outer o2 = new Outer();
> 
>    void main() {
>        Inner i1 = new Inner!(o1);
>        Inner i2 = new Inner!(o1);
> 
>        Inner i3 = new Inner!(o2);
>        Inner i4 = new Inner!(o2);
>    }

Thanks. That looks quite promising.

But it does not compile for me:
test.d(12): class test.Inner(alias outer) is used as a type
test.d(12): variable test.main.i1 voids have no value

> Having each Inner class parameterized with an alias, is like having a 
> compile-time constant member (the outer variable). This poses some 
> restrictions though: the outer classes variables cannot be declared 
> inside functions (because variables inside functions cannot be used as 
> alias parameters),

I'm do not exactly understand that. Where can I find documentation on that?

> and the Inner classes are no longer compatible 
> (covariant) with each other, although you can create a common Inner 
> superclass.

That's ok. I always had the perception that o1.Inner and o2.Inner are different types.

coxalan



More information about the Digitalmars-d mailing list