the behavior of opAssign

Sobaya sobaya007 at gmail.com
Mon Jan 29 09:23:55 UTC 2018


I found a strange behavior.

class A {
     void opAssign(int v) {}
}

class Test {
     A a;
     this() {
         a = new A(); // removing this causes compile error.
         a = 3; // cannot implicitly convert expression `3` of 
`int` to `A`
     }
}

void main() {
     // this is allowed.
     A a;
     a = 3;
}

Is it a compiiler's bug?


More information about the Digitalmars-d-learn mailing list