How to allow +=, -=, etc operators and keep encapsulation?

Jack jckj33 at gmail.com
Mon Apr 12 18:16:14 UTC 2021


Give this class:

```d
class A
{
	int X() { return x; }
	int X(int v) { return x = v;}

	private int x;
}
```

I'd like to allow use ```+=```, ```-=``` operators on ```X()``` 
and keep encapsulation. What's a somehow elegant way to do that?


More information about the Digitalmars-d-learn mailing list