How to disable assigning a value to a property?

jfondren julian.fondren at gmail.com
Tue Jul 6 15:36:34 UTC 2021


On Tuesday, 6 July 2021 at 15:24:37 UTC, jfondren wrote:
> 3. https://run.dlang.io/is/AJM6Vg - hybrid where ClockAssign 
> has an unsafe pointer that the compiler complains about :/

4.

```d
import std.stdio;

struct Field {
     void opAssign(int a) {
         writefln("Field.opAssign(%s)", a);
     }
}

struct ClockAssign {
     Field[] clocks;
     void opIndexAssign(int a, int b) {
         writefln("Register.clock(%s)", a);
         clocks ~= Field();
         clocks[$-1] = b;
     }
}

struct Register {
     ClockAssign clock;
}


void main() {
     Register register;
     register.clock[1] = 10;
     // register.clock = 10; // error
}
```


More information about the Digitalmars-d-learn mailing list