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

captain_fid bell.hue at gmail.com
Thu Mar 6 16:32:01 PST 2014


On Friday, 7 March 2014 at 00:10:20 UTC, bearophile wrote:
> 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

Going to have to buy the whole bar a round. Thanks bearophile for 
the quick fix!



More information about the Digitalmars-d-learn mailing list