Properties: a.b.c = 3

Steven Schveighoffer schveiguy at yahoo.com
Wed Jul 29 11:54:32 PDT 2009


On Wed, 29 Jul 2009 14:50:42 -0400, Ary Borenszweig <ary at esperanto.org.ar>  
wrote:

> Steven Schveighoffer wrote:
>> On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig  
>> <ary at esperanto.org.ar> wrote:
>>
>>> a.b.c = d;
>>>
>>> If b is anything that has a struct type, and c is anything else, the  
>>> statement must report an error.
>>  struct S
>> {
>>   int *x;
>>   void c(int n) {*x = n;}
>> }
>>  struct S2
>> {
>>   int n;
>>   S b() { return S(&n);}
>> }
>>  void main()
>> {
>>   S2 a;
>>   a.b.c = 5;
>> }
>>  Why should this not be allowed?
>
> Because in the general case it might not work.
>
> It's simple: if you disallow it, no bugs caused because of this can  
> exist. If you don't disallow it, sometimes it might work, sometimes it  
> won't work. Which option do you prefer as a programmer?

I prefer to have the power to create whatever I want without the telling  
me incorrectly that it won't work.

why allow any programming at all?  The programmer might write incorrect  
code!

-Steve



More information about the Digitalmars-d mailing list