No, you can't, because you are calling the function always with only one argument, you need a type with only one argument. Instead, you can use template by value (no typename or class)
One argument:
int foo(int x)
{
return x;
}
int foo(int x, int y)
{
return x+y;
}
typedef int (*foo_fcn)(int);
template<foo_fcn unary_func>
int bar(int k)
{
return unary_func(k);
}
int main()
{
bar<foo>(3);
return 0;
}
Two arguments:
int foo(int x)
{
return x;
}
int foo(int x, int y)
{
return x+y;
}
typedef int (*foo_fcn)(int, int);
template<foo_fcn unary_func>
int bar(int k)
{
return unary_func(k, k);
}
int main()
{
bar<foo>(3);
return 0;
}
Both:
int foo(int x) // first foo
{
return x;
}
int foo(int x, int y) // second foo
{
return x+y;
}
typedef int (*foo_fcn)(int);
typedef int (*foo_fcn_2)(int, int);
template<foo_fcn unary_func>
int bar(int k)
{
return unary_func(k);
}
template<foo_fcn_2 unary_func>
int bar(int a, int b)
{
return unary_func(a, b);
}
int main()
{
bar<foo>(3,1); // compiler will choose first foo
bar<foo>(4); // compiler will choose second foo
return 0;
}