jeudi 10 septembre 2020

no matching function call for

the code is as follows

#include <iostream>
#include <functional>

using namespace std;
template<class F, class ...Args>
result_of_t<F> foo(F&& f,Args&&... args){
    cout<<sizeof...(args);
    f(args...);
}

int main(){
    foo([](char a){ cout<<a<<'\n'; },'a');
    return 0;
}

while I compile the code, it says

template.cpp:12:38: error: no matching function for call to ‘foo(main()::<lambda(char)>, char)’

why the first statement of main function cannot match the function?

Aucun commentaire:

Enregistrer un commentaire