Hi!

I would like to pass arrays of objects to a function taking an array of parent class as argument. I try different things but unfortunately I have compilation errors each time.

The following example works with no array:

class A {
        int a;
}

class B extends A {
int b;
}

fun void plus(A arg) {
        arg.a ++;
}

B foo;

1 => foo.a;
plus (foo);
<<<"foo.a", foo.a>>>;




But When I try the same with arrays it doesn't compile:
[l13.ck]:line(22): argument type(s) do not match:
[l13.ck]:line(22): ... for function 'plus(...)' ...
[l13.ck]:line(22): ...(please check the argument types)

class A {
        int a;
}

class B extends A {
int b;
}

fun void plus(A arg[]) {
        for (0 => int i; i <  arg.size()     ; i++) {
        arg[i].a ++;
        }

}

B foo[2];

1 => foo[0].a;
2 => foo[1].a;
plus (foo);
<<<"foo[0].a", foo[0].a>>>;
<<<"foo[1].a", foo[1].a>>>;


Any idea ?

Thanks in advance and Happy new year!!

Julien

_______________________________________________
chuck-users mailing list
[email protected]
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

Reply via email to