#include <iostream>using namespace std;class Student{public: Student (const string& name): M_name (name) {} void who (void) { cout << m_name << endl; } string m_name; static int s_add (int &NBSP;A,INT&NBSP;B) { return a+b; }} ; Int main (void) { //member function pointer void (Student::* pwho) (void) &NBSP;=&NBSP;&STUDENT::WHO;&NBSP;&NBSP;&NBSP;&NBSP;STUDENT&NBSP;S1 ("Zhnangfei"); STUDENT&NBSP;S2 ("Zhaoyun"); (s1.*pwho) (); student* ps = &s2; (ps->*pwho) (); //pointer to static member function int (*Padd) (Int,int) = Student::s_add; //int (Student::* padd1) (int,int) = Student::s_add; error cout << padd (100,200) << endl; return 0;} Pointer to member function (that is, function pointer): Type () (parameter type) = & class Name:: member function name (note that the address character must be added before the class name & or an error) pointer to a static member function (or function pointer): type () (parameter type) = student::s_add (note type can be added without &)
This article is from the "12208412" blog, please be sure to keep this source http://12218412.blog.51cto.com/12208412/1866470
member function pointers and pointers to static member functions