toString ugliness

Christopher Wright dhasenan at
Sun Dec 7 12:29:22 PST 2008

Ary Borenszweig wrote:
> Jarrett Billingsley escribió:
>> On Sun, Dec 7, 2008 at 7:12 AM, Ary Borenszweig <ary at> 
>> wrote:
>>>> definition of toString that does match.  Most of the time ADL leads to
>>>> confusing behavior, which is why it was dropped in D.
>>> But the overloading is obvious! It looks for toString(...) and it 
>>> founds it
>>> in the class, but the overloading is wrong. So for me, it should keep
>>> looking in the enclosing scopes.
>> That's why I said "*most* of the time" ;)  I'll agree that it's a bit
>> counterintuitive, but I'd rather have the compiler be a little stupid
>> in this regard than to pay the price of unexpected function matches
>> for a little bit of convenience.
> Ah, I see. Well, I'd like to see such an example then. :-P

It usually won't be an issue, I think. You'll give your functions 
descriptive names, and you won't have overloads in different scopes that 
take similar arguments. So any example I give will probably seem 
contrived. I certainly have only encountered this compiler error a bare 
handful of times, and only with toString.

That said, errors of this kind would be difficult to track down, and the 
workaround is very simple once you know it -- and not that difficult to 
come up with if you don't. I think I came up using .toString without 
having anyone tell me about it, and if I hadn't, I would have used the 
fully qualified name (or an alias).

More information about the Digitalmars-d mailing list