Having the following functions
void print(int a) { cout << a << endl; }
void print(std::string a) { cout << a << endl; }
You can do the following template
template <class T> void printT(T a) { print(a); }
Is there some mechanism to parametrize the function name? Something like this:
template <class T, class F> void anyT(T a) { F(a); }
I don't need to be a function template, just some mechanism to achieve the same.
Yes, you could pass the caller as a function pointer that takes as input T
like below:
template <class T> void anyT(T a, void(*f)(T)) {
f(a);
}
Live Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With