//ConsoleApplication34.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<iostream>using namespacestd;classParent { Public: Parent () {//cout << "I am Dad" << Endl; } Virtual voidprint () {cout<<"I'm the Father ."<<Endl; }Private: intA;};classChild: PublicParent { Public: Child () {}voidprint () {cout<<"I'm a son ."<<Endl; }Private: intb;};intMain () {//return value type (Domain action::* function pointer name) (method parameter signature) This one is not a parameter.//void (Child::* fptr) (), non-parametric//void (Child::* fptr) (int,int);//Explanation: No return value type scope is a function pointer that belongs to the child class, that is, a function pointer to any parameterless member function that points to the child class void(Child::*fptr) (); //a function pointer that eventually binds to the print function of the child classFptr= &Child ::p rint;; Child arr[]={child (), child (), Child ()}; //Parent *p; //child* C; //p = arr; //C = arr; //P->print (); //C->print (); //p++; //C + +; //P->print (); //C->print (); //p++; //C + +; //P->print (); //c->print (); (*ARR.*FPTR) ();//equivalent to Arr[0].print (); (* (arr+1).*fptr) (); (* (arr +2).*fptr) (); System ("Pause"); return 0;}
C + + pointer to a function of a class member function