In this shortened example (not real world code), I'm attempting to call Callback
with an int &
, however, when going via the CallMethod
method, the template parameter is interpreted as an int
, meaning it can't convert it to the target parameter type.
Is this possible? I know I can cast the parameter to the correct type when calling CallMethod
, however I'd like the solution to be implicit if possible.
#include <functional>
#include <iostream>
using namespace std;
void Callback(int &value)
{
value = 42;
}
template <typename Method, typename ...Params>
void CallMethod(Method method, Params ...params)
{
method(std::forward<Params>(params)...);
}
int main()
{
int value = 0;
CallMethod(&Callback, value);
cout << "Value: " << value << endl;
return 0;
}