I have the following lines of code. I don't understand why template parameters need to be given (the highlighted part). Isn't the compiler able to deduce the type automatically? Since myfunc is defined already, I would think it is obvious which Combiner needs to be called.
#include <functional> #include <iostream> template <class T> void Combiner(double a, std::function<void (T)> func){ return func(std::to_string(a)); } void myfunc(std::string a){ std::cout << a << std::endl; return; } int main(){ Combiner***<std::string>***(12, myfunc); }
void Combiner(double a, T func){. Still looking at the "why" part.myfunc≠std::function<void(std::string)>. Add thisstd::function<void(std::string)> fn_myfunc = myfunc;thenCombiner(12, fn_myfunc);