As you call your function template, the package of Args
template parameters will be output from two sources:
- The type of the pointer to the member function is
int (Calculator::*)(const int&, const int&)
- The actual types of arguments (
*a, *b)
that you passed for the parameter package to the function are int &, int &
For successful deduction, the result must match exactly. Obviously, they do not.
This is not new or special for variable templates. You have the same problem if you try to make std::max(1, 1.5)
- the compiler outputs int
from one argument, double
from another, and the output is impossible, because there are two conflicts.
The simplest fix probably consists of two packages:
template <typename T, typename R, typename... Args1, typename... Args2> R call(R (T::*fn)(Args1...), T *t, Args2&&... args) { return ((*t).*fn)(std::forward<Args2>(args)...); }
source share