Template method and type resolution of return type

matovitch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 20 00:52:07 PDT 2014


On Sunday, 20 April 2014 at 00:55:31 UTC, David Held wrote:
> On 4/19/2014 3:31 PM, Andrej Mitrovic via Digitalmars-d-learn 
> wrote:
>> [...]
>> struct S
>> {
>>     int get()  { return 0; }
>>     T get(T)() { return T.init; }
>> }
>>
>> void main()
>> {
>>     S s;
>>     float x = s.get();  // which overload? (currently int 
>> get())
>> }
>
> Isn't this just because concrete methods are better overload 
> candidates than method templates?
>
> Dave

struct S
{
    ubyte get()  { return 0 ; }
    float get()  { return 0.; }
}

void main()
{
    S s;
    float x = s.get();  // does'nt know which overload, does'nt 
compile.
}


More information about the Digitalmars-d-learn mailing list