I would like to simplify foo
by using a typedef
to represent the type for the ptr
argument.
#include <iostream>
template <unsigned N>
int foo (int (*ptr) (const char (*)[N])) {
char good[N] = "good";
return ptr(&good);
}
int bar (const char (*x)[5]) {
std::cout << *x << "\n";
return 0;
}
int main ()
{
return foo(bar);
}
I would like to write foo()
to be more like this:
template <unsigned N>
int foo (FUNCTION_TYPE *ptr) {
char good[N] = "good";
return ptr(&good);
}
I tried using a traits like helper class, but that failed. Is there a proper way to create a typedef
for FUNCTION_TYPE
?