I was wondering if it is possible to achieve something like this without error:
#include <iostream> template<typename T> T Sum(T _arg, T (*callbackFunction)(T)) { T result = (*callbackFunction)(_arg); return result; } template<typename T> T Callback(T _arg) { std::cout << "Callback is called" << std::endl; return _arg; } int main() { std::cout << Sum(10.2f, Callback); getchar(); return 0; }
This is what I get:
cannot use function template 'T Callback(T)' as a function argument could not deduce template argument for 'T' from 'float'
user2946316
source share