how to assign to shared obj.systime?

mw mingwu at gmail.com
Fri Jul 10 17:18:25 UTC 2020


On Friday, 10 July 2020 at 08:48:38 UTC, Kagamin wrote:
> On Friday, 10 July 2020 at 05:12:06 UTC, mw wrote:
>> looks like we still have to cast:
>> as of 2020, sigh.
>
> Why not?

Because cast is ugly.

I've also tried this:
```
class A {
         SysTime time;
         synchronized setTime(ref SysTime t) {
                 time = t;
         }
}

void main() {
         shared A a = new A();
         SysTime time;
         a.setTime(time);
}
```

Same Error: template std.datetime.systime.SysTime.opAssign cannot 
deduce function from argument types !()(SysTime) shared, 
candidates are:
/usr/include/dmd/phobos/std/datetime/systime.d(659,17):        
opAssign()(auto ref const(SysTime) rhs)

However, we have a lock on the owning shared object, still we 
need cast to make it compile:
```
       cast()time = t;
```




More information about the Digitalmars-d-learn mailing list