How does template argument deduction work when an overloaded function is involved as an argument?

前端 未结 1 670
抹茶落季
抹茶落季 2021-01-07 18:55

This is the more sophisticated question mentioned in How does overload resolution work when an argument is an overloaded function?

Below code compiles witho

相关标签:
1条回答
  • 2021-01-07 19:04

    As noted in the answer to your linked question:

    [temp.deduct.call]/6:When P is a function type, pointer to function type, or pointer to member function type:

    — If the argument is an overload set containing one or more function templates, the parameter is treated as a non-deduced context.

    Since the overload set contains a function template, the parameter is treated as a non-deduced context. This causes template argument deduction to fail:

    [temp.deduct.type]/4: [...]If a template parameter is used only in non-deduced contexts and is not explicitly specified, template argument deduction fails.

    And this failed deduction gives you your error. Note that if you explicitly specify the arguments, the code compiles successfully:

    bar<int,double>(foo);
    

    Live demo

    0 讨论(0)
提交回复
热议问题