C++ 变量模板函数没有匹配的函数调用

C++ 变量模板函数没有匹配的函数调用,c++,c++11,C++,C++11,代码如下 template.cpp: In function ‘int main()’: template.cpp:12:38: error: no matching function for call to ‘foo(main()::<lambda(char)>, char)’ 12 | foo([](char a){ cout<<a<<'\n'; },'a'); |

代码如下

template.cpp: In function ‘int main()’:
template.cpp:12:38: error: no matching function for call to ‘foo(main()::<lambda(char)>, char)’
   12 |  foo([](char a){ cout<<a<<'\n'; },'a');
      |                                      ^
template.cpp:6:16: note: candidate: ‘template<class F, class ... Args> std::result_of_t<F> foo(F&&, Args&& ...)’
    6 | result_of_t<F> foo(F&& f,Args&&... args){
      |                ^~~
template.cpp:6:16: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10.2.0/bits/move.h:57,
                 from /usr/include/c++/10.2.0/bits/nested_exception.h:40,
                 from /usr/include/c++/10.2.0/exception:148,
                 from /usr/include/c++/10.2.0/ios:39,
                 from /usr/include/c++/10.2.0/ostream:38,
                 from /usr/include/c++/10.2.0/iostream:39,
                 from template.cpp:1:
/usr/include/c++/10.2.0/type_traits: In substitution of ‘template<class _Tp> using result_of_t = typename std::result_of::type [with _Tp = main()::<lambda(char)>]’:
template.cpp:6:16:   required by substitution of ‘template<class F, class ... Args> std::result_of_t<F> foo(F&&, Args&& ...) [with F = main()::<lambda(char)>; Args = {char}]’
template.cpp:12:38:   required from here
/usr/include/c++/10.2.0/type_traits:2570:11: error: invalid use of incomplete type ‘class std::result_of<main()::<lambda(char)> >’
 2570 |     using result_of_t = typename result_of<_Tp>::type;
      |           ^~~~~~~~~~~
/usr/include/c++/10.2.0/type_traits:2344:11: note: declaration of ‘class std::result_of<main()::<lambda(char)> >’
 2344 |     class result_of;
      |           ^~~~~~~~~

#包括
#包括
使用名称空间std;
模板
_t foo的结果(F&&F,Args&&…Args){

cout,因为无法推断
foo
的返回类型

结果_获取函子Args.的完整签名。在那里缺少

template<class F, class ...Args>
result_of_t< F(Args...) > foo(F&& f,Args&&... args){
    cout<<sizeof...(args);
    f(args...);
}
模板
_tfoo(F&&F,Args&&Args)的结果{

请提供完整的编译器错误消息,它可能会说明失败的原因请注意,
result\u在C++17中被弃用,在C++20中被删除,使用
invoke\u result
decltype
应该更好。该函数还缺少一个return语句:。那么问题将是
void
return;返回n SFINAE…意味着答案只适用于空lambdas。
template<class F, class ...Args>
result_of_t< F(Args...) > foo(F&& f,Args&&... args){
    cout<<sizeof...(args);
    f(args...);
}