In your version, a trifle is forgotten - the fact that a non-static member function requires an object for which it is called. So you just can't call it, you need an object.
Or static function.
Here it is - easily:
class A1 { public: static void show() { std::cout << "A1" << std::endl; } }; class B1 { public: static void show() { std::cout << "B1" << std::endl; } }; void callf(void (*fp)()) { fp(); } int main() { callf(&A1::show); callf(&B1::show); return 0; }
If, however, not static - for example, here:
class A1 { public: void show() { std::cout << "A1" << std::endl; } }; class B1 { public: void show() { std::cout << "B1" << std::endl; } }; template<class T> void callf(T& t, void (T::*f)()) { (t.*f)(); } int main() { A1 a; B1 b; callf(a,&A1::show); callf(b,&B1::show); return 0; }
callf()is a special case ofstd::invoke(). - jfs