See below example. Can’t think of a reason why this is not possible. Am I really forced to introduce a using decl or typedef? Any other reasonable workarounds?
struct Foo {
public:
int get_res() { return 1; }
int get_res(int i) { return 1; }
};
// Works!
struct Accessor {
using overload = int(Foo::*)();
static constexpr overload resGetter = &Foo::get_res;
};
// error: expected unqualified-id before ')' token
struct Accessor {
static constexpr int(Foo::*)() resGetter = &Foo::get_res;
};
>Solution :
struct Accessor2 {
static constexpr int(Foo::*resGetter)() = &Foo::get_res;
};
That’s why you don’t usually write member function pointers like this — it looks strange, and people make errors.
Typedefs do not generate any code — you can use them as much as you want to make your code readable.