we all know that C + + class has three member functions, static(static), nonstatic (non-static), virtual (dummy) various member functions have different pointers, here is a complete example: ( Pay attention to the difference of Red color )class A{Public :static void Staticmember () {cout<< "Static" <<ENDL;} Static membervoid nonstatic () {cout<< "nonstatic" <<ENDL;} nonstatic membervirtual void Virtualmember () {cout<< "virtual" <<endl;};/ /virtual member};int main (){A;//static member, obtained is the actual address of the function in memory, and because the static member is global, you cannot use a:: Qualifier Void (*ptrstatic) ()= &A::staticmember; //nonstatic member gets the actual address of the function in memory void (A::* ptrnonstatic) () = &A::nonstatic;The //virtual function obtains the offset value from the virtual function table, which guarantees the same polymorphic effect when the pointer is called . void (A::* ptrvirtual) () = &A::virtualmember;//Use of function pointersptrstatic ();( a.*ptrnonstatic) ();( a.*ptrvirtual) ();}
How to get a pointer to a class member in C + +