【发布时间】:2018-12-28 09:35:37
【问题描述】:
我想知道为什么在下面的代码中编译器无法使用 lambda 作为函数 foo() 的参数(模板参数推导/替换失败),而一个简单的函数可以工作:
template<class ...Args>
void foo(int (*)(Args...))
{
}
int bar(int)
{
return 0;
}
int main() {
//foo([](int) { return 0; }); // error
foo(bar);
return 0;
}
intel 编译器(18.0.3 版)
template.cxx(12): error: no instance of function template "foo" matches the argument list
argument types are: (lambda [](int)->int)
foo([](int) { return 0; }); // error
^
template.cxx(2): note: this candidate was rejected because at least one template argument could not be deduced
void foo(int (*)(Args...))
有什么想法吗?
【问题讨论】:
标签: c++ templates lambda template-argument-deduction