How to disable assigning a value to a property?

drug drug2004 at bk.ru
Tue Jul 6 10:24:45 UTC 2021


06.07.2021 13:06, Jack Applegame пишет:
> Code:
> ```d
> import std.stdio;
> 
> struct Field {
>      void opAssign(int a) {
>          writefln("Field.opAssign(%s)", a);
>      }
> }
> 
> struct Register {
>      Field clock(int a) {
>          writefln("Register.clock(%s)", a);
>          return Field();
>      }
> }
> 
> 
> void main() {
>      Register register;
>      register.clock(1) = 10; // works, good
>      register.clock = 10;    // works too, how to disable it?
> }
> ```
> How to disable `register.clock = 10;` but allow `register.clock(1) = 10;`?
> I want to get a compilation error on `register.clock = 10;`
> 

Something like using different types for arguments in `Register.clock` 
and `Field.opAssign`?


More information about the Digitalmars-d-learn mailing list