variable _param_0 cannot be read at compile time

learnfirst1 learnfirst1 at gmail.com
Wed Aug 8 13:03:16 UTC 2018


On Wednesday, 8 August 2018 at 12:57:43 UTC, learnfirst1 wrote:
> Why this is a error ?
>

this code example can explain what I am try to do here:

struct M {
         int i;
         S*[100] s;
}
struct S {
         M* mp;
         bool x;
}


S* add(A...)(ref A a) {
         __gshared s = S(a);
         alias m = a[0];
         m.s[m.i++] = &s;
         return &s;
}

void main(){
         __gshared M m = M(0);
         __gshared S s = S(&m, false);
         m.s[m.i++] = &s;
         auto p = add(&m, true);  // variable _param_0 cannot be 
read at compile time
}

because S has the optional ctor parameters, I can not use 
template alias param here( some how not work) .





More information about the Digitalmars-d-learn mailing list