auto

Ary Borenszweig ary at esperanto.org.ar
Wed Aug 12 08:32:40 PDT 2009


Jarrett Billingsley wrote:
> On Wed, Aug 12, 2009 at 9:18 AM, Ary Borenszweig<ary at esperanto.org.ar> wrote:
>> This compiles and runs in D2:
>>
>> --
>> import std.stdio;
>>
>> auto foo() {
>>    return 1;
>> }
>>
>> void main() {
>>    writefln("%s", foo());
>> }
>> --
>>
>> Since when a non-templated function can have its return type deduced? :)
> 
> Cool.  I'm testing this and it really does seem to be non-templated.
> So of course, the first thing I tried was this:
> 
> class A
> {
>     auto foo() { return 0; }
> }
> 
> class B : A
> {
>     auto foo() { return 5; }
> }
> 
> but DMD crashes.  :P

Now that it also works in Descent I can see it's because function 
overloading is treated before function return type inference, and the 
return types for the functions at those moments are null...



More information about the Digitalmars-d mailing list