Operator declaration

Dom Disc dominikus at scherkl.de
Thu Apr 23 15:04:59 UTC 2026


```d
struct MyType
{
    ubyte val;
    MyType opOpAssign(string op)(const MyType x) if(op =="^^")
    {
       val ^^= x.val;
    }
}

MyType m;
m ^^= m;
```

==> cannot implicitly convert expression 
`pow(cast(int)__powtmp1234, cast(int)x.val)` of type `int` to 
`ubyte`

This is one of the bugs that we bought with the strange policy 
that operators do NOT return same type as their operands.
"convert everything to int but not back" :-(

But in this special case I cannot see how to avoid this. Where do 
I need to put the cast to make this conversion explicit?!?


More information about the Digitalmars-d-learn mailing list