I recently found that function pointer syntax can be simplified when using the following helper class:
template<typename Sig>
struct Fun {
typedef Sig* Ptr;
};
It allows me a pointer to void() as follows:
typedef Fun<void()>::Ptr fun_ptr;
fun_ptr f = foo;
I would like to create a similar utility for to create a typedef to member function pointers. It would allow the following syntax:
struct Foo {
void bar() {}
};
typedef MemFun<Foo, void()>::Ptr bar_type;
bar_type b = &Foo::bar;
However, I can’t figure out the typedef syntax:
template<class T, typename Sig>
struct MemFun {
// How to use T and Sig to create member function typedef?
};
Can anyone help?
When the
Sigargument is a function type, the resulting type is a pointer to member function, not a pointer to data member. In particular, in this context function types likevoid() constare valid.