I was going to make many similar functions,
So I have wondered whether I use templates or macros.
Since I should use function pointers of each function, I tried to
compile the code below to test it, but an error occured.
#include <stdio.h>
#define make_print_macro(T) \
void print_macro_##T( T a ) \
{ \
printf( "%d\n", a); \
}
make_print_macro(int);
#define print_macro(T) print_macro_##T
template<class T>
void print_tmplt( T a )
{
printf ( "%d\n", a );
}
int main()
{
print_macro(int)( 10 );
print_tmplt<int>( 10 );
printf ( "%p\n", (void *)(print_macro(int)) );
//printf ( "%p\n", (void *)(print_tmplt<int>) ); // THIS CODE
return 0;
}
All works fine except the line I marked 'THIS CODE'.
error: cannot resolve overloaded function `print_tmplt' based on
conversion to type `void*'
Can't I obtain a function pointer to an instance of a template so that
I must use macro in this case?