可能重複:
Why can't my C++ compiler deduce template argument for boost function?
Isn't the template argument (the signature) of std::function part of its type?隱式轉換用的std ::功能
我有以下幾點:
#include <functional>
void Foo(std::function<void()> );
void Foo(std::function<void(int)>);
void Bar();
int main()
{
Foo(Bar); // Error: ambiguous
Foo([](){}); // Error: ambiguous
Foo(std::function<void()>(Bar )); // Ok
Foo(std::function<void()>([](){})); // Ok
}
我可以讓前兩行在main()工作中沒有函數式的cas t在最後兩行?也許用std :: enable_if解決方案?