Negating a short?
Salih Dincer
salihdb at hotmail.com
Wed Nov 6 16:38:40 UTC 2024
On Wednesday, 6 November 2024 at 16:25:40 UTC, Salih Dincer wrote:
> In response to Andy and Matheus, I think implementing your own
> type might be a solution:
Even in my own type, single overload was enough. So I have to
correct my mistake:
```d
void main()
{
Short foo = { -21 };
s *= -1;
foo = foo * -2;
assert(foo.s == 42);
}
struct Short
{
short s;
auto opBinary(string op: "*")(int rhs)
{
auto result = s * rhs;
return Short(cast(short)result);
}
}
```
SDB at 79
More information about the Digitalmars-d-learn
mailing list