dynamic classes and duck typing

Denis Koroskin 2korden at gmail.com
Wed Dec 2 02:19:34 PST 2009


On Wed, 02 Dec 2009 00:01:41 +0300, Bill Baxter <wbaxter at gmail.com> wrote:

> On Tue, Dec 1, 2009 at 12:38 PM, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>> On Tue, 01 Dec 2009 15:06:27 -0500, Pelle Månsson  
>> <pelle.mansson at gmail.com>
>> wrote:
>>
>>> Steven Schveighoffer wrote:
>>
>>>>  Isn't opBinary almost identical to opDispatch?  The only difference I
>>>> see is that opBinary works with operators as the 'symbol' and  
>>>> dispatch works
>>>> with valid symbols.  Is it important to distinguish between operators  
>>>> and
>>>> custom dispatch?
>>>>  -Steve
>>>
>>> opBinary is a binary operator, opDispatch can be anything. I think they
>>> should be kept separate.
>>
>> You could say the same thing about dynamic properties.  How come we  
>> don't
>> split those out as opProperty?
>
> That's because of what Andrei pointed out:  &a.b .
> The compiler can't tell if you want a delegate to the method b, or the
> address of a property b.
>

Technically, you are wrong. There is the same ambiguity without function  
overloads:

void foo(int a);
void foo(float a);

auto dg = &foo; // which one of the two overloads is chosen and why?

Resolving properties is much easier: property and function names can't  
overlap, i.e. you can't have property *and* any function with the same  
name.



More information about the Digitalmars-d mailing list