About Immutable struct members and arrays.

Jack Applegame via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 6 14:04:49 PST 2016


import std.algorithm;

struct Bar {
     const int a;
     int b;
}

void main() {
     Bar[1] arr;
     Bar bar = Bar(1, 2);
     bar[0].b = 4;
     move(bar, arr[0]);       // ok
     arr[1] = bar;            // fail, why?
     move(Bar(1, 2), arr[0]); // fail, why source parameter isn't 
auto ref?
}



More information about the Digitalmars-d-learn mailing list