Best way to reference an array in a child class...

bearophile bearophileHUGS at lycos.com
Thu Mar 6 16:10:19 PST 2014


captain_fid:

> struct S
> {
>   int a;
>   string b;
> }
>
> class A
> {
>    S[] items;
>    abstract void doit();
> }
>
> class B: A
> {
>    this() {items = [ {10, "first"}, {20, "second"}];}    // 
> line 21
>    override void doit() { }
> }
>
> (21): Error: found '}' when expecting ';' following statement
> (21): Error: found ',' instead of statement

For reasons I don't know that {} syntax doesn't always work in D. 
So try:

this() {
     this.items = [S(10, "first"), S(20, "second")];
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list