Facing problems with Class Properties
Jesse Phillips
jessekphillips+D at gmail.com
Fri Dec 10 12:02:56 PST 2010
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.
More information about the Digitalmars-d-learn
mailing list