#include <functional>
using namespace std;
template<class CharType>
void f1(CharType* str, function<bool(CharType)> fn_filter)
{}
template<class CharType>
void f2(CharType* str, function<bool(char)> fn_filter)
{}
void f3(char* str, char c)
{
auto fn_filter = [=](char e) -> bool
{
return e == c;
};
f1(str, fn_filter); // error C2784
f2(str, fn_filter); // OK
}
int main()
{
f3("ok", 'k');
}
// error C2784: 'void f1(CharType *,std::function<bool(CharType)>)'
// : could not deduce template argument for 'std::function<bool(CharType)>'
// from 'f2::<lambda_36be5ecc63077ff97cf3d16d1d5001cb>'
我的编译器是 VC++ 2013。
为什么f1
不能按预期工作?