No implicit opOpAssign for structs with basic types?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sat Apr 4 14:19:10 UTC 2020
On Saturday, April 4, 2020 4:22:29 AM MDT Robert M. Münch via Digitalmars-d-
learn wrote:
> D doesn't have implicit operators for structs?
>
> struct S {float a, float b};
> S a = {1, 5};
> S b = {2, 5);
>
> a += b;
> Error: a is not a scalar, it is a S
>
> So I really have to write an overloaded operator for such cases?
You could just use the constructor syntax. e.g.
S a = S(1, 5);
S b = S(2, 5);
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list