Operator "+=" overloading for class?

Ki Rill rill.ki at yahoo.com
Mon Dec 18 03:39:16 UTC 2023


On Sunday, 17 December 2023 at 07:05:12 UTC, Adam D. Ruppe wrote:
> On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
>> [...]
>
> check what `op` is. pretty sure it is "+" not "+=" so your 
> element isnt' saved anywhere. also a bit iffy there isn't a 
> member here to work on

Yes, op is '+'. What do you mean by it isn't saved anywhere? I 
tried reassigning to `this` and returning it, but it fails.

I want to achieve this, but with '+=':
```d
auto g = value(0);
g = g + value(3);

// here it should just create a new instance 'g + value(3)' and 
save it into 'g'
g += value(3);
```

Do you have an advice on how to achieve it?


More information about the Digitalmars-d-learn mailing list