Given
struct A {
int foo(double a, std::string& b) const;
};
I can create a member function pointer like this:
typedef int (A::*PFN_FOO)(double, std::string&) const;
Easy enough, except that PFN_FOO needs to be updated if A::foo‘s signature changes. Since C++11 introduces decltype, could it be used to automatically deduce the signature and create the typedef?
Yes, of course:
typedef decltype(&A::foo) PFN_FOO;You can also define type alias via
usingkeyword (Thanks to Matthieu M.):using PFN_FOO = decltype(&A::foo);