As is, it is impossible.
The problem is that the template is intrinsically safe in type. However, your example is not. There is nothing inherent in the name foo2that holds back the set of types on which it can be applied!
To illustrate this problem, consider a typical member function:
struct Foo { int doit(double x, double y); };
int (Foo::*)(double,double).
, , , .
, doit ... , :
class foo {
public:
void foo1(int x, int y)
{
dispatch(&fooA::foo1, &fooB::foo1, &fooC::foo1, x, y);
}
void foo2(int x, double y, void *z)
{
dispatch(&fooA::foo2, &fooB::foo2, &fooC::foo2, x, y, z);
}
private:
template <typename... Args>
void dispatch(int (fooA::* f)(Args...),
void (fooB::* g)(Args...),
void (fooC::*h)(Args...),
Args... args)
{
switch((m_Member.*f)(args...)) {
case 1: (m_Member1.*g)(args...); return;
case 2: (m_Member2.*h)(args...); return;
}
}
fooA m_Member;
fooB m_Member1;
fooC m_Member2;
};
, .