@property needed or not needed?

Maxim Fomin maxim at maxim-fomin.ru
Mon Jan 28 06:28:29 PST 2013


On Monday, 28 January 2013 at 14:09:20 UTC, Dicebot wrote:
> On Monday, 28 January 2013 at 14:00:16 UTC, Maxim Fomin wrote:
>> Returning void instead of int in the example break assignment 
>> chaining a = b = c. Besides, how such implicitly defined 
>> functions may call user defined code (check input validity, 
>> call events, etc.)?
>
> It should not if evaluating the value of (b = c) will call 
> getter for b.

Why getter and not setter? Expression a = b = c = d should call 
getter for d and setter for rest of them. And if c setter returns 
void the chain breaks.


struct S
{
     int _priv;
     @property void /*int*/foo(int i) //uncommment to fix
     {
         _priv = i;
         //return i;
     }
     @property int foo()
     {
         return _priv;
     }
}

void main()
{
     int a, b, c;
     a = b = c;

     S s1, s2, s3;
     s1.foo = s2.foo = s3.foo = 1;
}


More information about the Digitalmars-d mailing list