Ambiguity in std::function Template Argument Signatures
The ambiguity arises when both function
To illustrate this, consider the class:
<code class="cpp">template<class Signature> class myfunc{ public: template<class Func> myfunc(Func a_func){ // ... } };</code>
When the compiler attempts to find viable functions for an overload set, it searches for potential conversions. In this case, both constructors of myfunc accept anything, allowing the conversion from int(*)() to myfunc
Thus, when calling a(x) or a(y), the compiler encounters two viable functions, resulting in ambiguity.
Resolution
The template argument signature of std::function is part of its type when declaring and defining functions. However, during object construction, the signature is ignored.
To circumvent the ambiguity, one can:
The above is the detailed content of Why Does `std::function` Lead to Ambiguity in Template Argument Signatures?. For more information, please follow other related articles on the PHP Chinese website!