If you have this generic function:
template<class type, class ret, class atype1, class atype2, class atype3>
ret call3(type *pClass, ret(type::* funcptr)(atype1, atype2, atype3), atype1 arg, atype2 arg2, atype3 arg3)
{
//do some stuff here
return (pClass->*funcptr)(arg, arg2, arg3);
}
and you do this:
class MyClass
{
public:
void test(int, int, int){};
void test(int, int){};
void test(int, int, const char *){}; //comment this line, and it works fine.
};
...
MyClass *a = new MyClass();
call3(a, &MyClass::test, 1, 2, 3);
g++ will say:
no matching function for call to `call3(MyClass*&, <unknown type>, int, int, int)'
Is there any way to fix this?
(My code is probably very bad also since I’m not very good at C++.)
You can explicitly specify which template to use.
If you rearange the order of your template parameters, you can get the MyClass and void deduced from the argument, so the call when needing an overload will look like this:
Note that when you dont actually need the explicit overload resolution it can still be