property += operator

SrMordred patric.dexheimer at gmail.com
Thu May 10 19:50:58 UTC 2018


On Thursday, 10 May 2018 at 19:41:41 UTC, Dlang User wrote:
> On 5/10/2018 1:43 PM, SrMordred wrote:
>> [...]
>
> I am relatively new to D and I was under the impression that 
> that was a limitation of @property functions.
>
> But, re-reading the language reference, it gave this example 
> (it returns something from the write property, which seems 
> odd), I modified to add refs, and then it seems to work, but I 
> am not sure if it is correct or not:
>
> import std.stdio;
>
> struct Foo
> {
>     @property ref int data() { return m_data; } // read property
>
>     @property ref int data(int value) { return m_data = value; 
> } // write property
>
>   private:
>     int m_data;
> }
>
> void main()
> {
> 	Foo f;
> 	f.data = 5;
> 	f.data++;
> 	f.data+= 2;
> 	writeln(f.data);
> 	
> }

this didn´t work either.
note that 'f.data+= 2;' don't call the write property


More information about the Digitalmars-d-learn mailing list