inner member classes in final outer class

Matti Niemenmaa see_signature at for.real.address
Sun Sep 16 08:58:14 PDT 2007


coxalan wrote:
> Matti Niemenmaa Wrote:
>> coxalan wrote:
>>> 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
>> Probably because he uses "Inner i[1234]" where he should use "Inner!(o[1234])
>> i[1234]". The easiest solution is to use "auto" on the left-hand side of the
>> assignments.
> 
> Thanks. Now I get:
> test.d(5): static assert  is false
> 
> Disclaimer: I'm quite new to D.

Alright, I took a closer look and this compiles:

class Outer {
}

class Inner(alias outer) {
	static assert(is(typeof(outer) : Outer)); // Just a check
}

final Outer o1;
final Outer o2;

static this() {
	o1 = new Outer;
	o2 = new Outer;
}

void main() {

	auto i1 = new Inner!(o1);
	auto i2 = new Inner!(o1);

	auto i3 = new Inner!(o2);
	auto i4 = new Inner!(o2);
}

-- 
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi



More information about the Digitalmars-d mailing list