d coder Wrote: > The issue is that when I try to compile the program, I get the error > bug.d(10): Error: no property 'length' for type 'test.Bar' > > I am explicitly checking the field type, and I am making sure that the field > is an array type, before looking for its length. So I am not sure why this > error appears. Please guide me. > > Regards > Cherry > > import std.stdio; > class BaseClass { } > > class Bar: BaseClass { } > > class Foo: BaseClass { > this() { > foreach(i, f; this.tupleof) { > if (is (typeof(f) : BaseClass[])) { > for (size_t j = 0; j < f.length; ++j) { > f[j] = new typeof(f[j]) (); > } > } > if (is(typeof(f) : BaseClass)) { > f = new typeof(f) (); > } > } > } > Bar instance1; > Bar instance2; > Bar [10] instances; > } > > unittest { > Foo foo; > foo = new Foo; > }
typeof() and is() are compile time constructs. Change your if statements to static if.