Is it possible to deduce the type of the class T from its pointer to memmber T::*f as shown below.
struct Foo
{
void func(){}
};
template<typename T, void (T::*f)()>
void bar()
{
}
int main()
{
bar<Foo,Foo::func>();
// bar<Foo::func>(); // Desired
}
In C++11/14 I would say no, unless you accept to deduce it by passing the pointer as a function argument:
template<typename T>
void bar(void(T::*f)())
{
}
int main()
{
bar(&Foo::func);
}
In C++17 you can have a single parameter function template as shown by @Jarod42, but you don't have the type T deduced anyway (if it was the purpose, as it seems to be from the question).
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