inner member classes in final outer class

coxalan coxalan at web.de
Thu Sep 20 09:05:12 PDT 2007


Matti Niemenmaa Wrote:

> coxalan wrote:
> > Matti Niemenmaa Wrote:
> >> 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);
> >> }
> >>
> > One last question on this:
> > Is it possible to do the same with D version 1?
> > 
> > The current code comples with DMD v2.004, but with DMD 1.020 I get:
> > 
> > forum.d(16): Error: cannot modify final variable 'o1'
> > forum.d(17): Error: cannot modify final variable 'o2'
> 
> Make o1 and o2 const instead of final.
> 
> -- 
> E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi

Thanks!

~coxalan



More information about the Digitalmars-d mailing list