I have the following functions in class "C"
class C
{
template<typename T> void Func1(int x);
template<typename T> void Func2(int x);
};
template<typename T> void C::Func1(int x)
{
T a(x);
}
template<typename T> void C::Func2(int x)
{
T a(x);
}
The functions uses templates only in the implementation. The signature does not contain template parameters.
Is it possible to define pointers to such template functions?
I tried the following definition but it results compilation error.
typedef template<typename T> void (СSomeClass::*TFuncPtr)(int);
Once instantiated, a member function template is just a normal member function, so you can use a normal member function pointer (best typedef
'd like below):
typedef void (C::*mem_fun_ptr)(int);
mem_fun_ptr p = &C::Func1<Bar>;
// IMPORTANT -- ^^^^^
The underlined part is the important part. You can't make a pointer to a function template, but you can make a pointer to an instantiated function template.
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