#include "stdio.h" class maths { private : void square ( int a ) const { printf ( "The square of %d is %d\n", a, a * a ) ; } void cube ( int a ) const { printf ( "The cube of %d is %d\n", a, a * a * a ) ; } void fourthpower ( int a ) const { printf ( "The fourth power of %d is %d\n", a, a * a * a * a ) ; } void ( maths :: * functionpointers [ 3 ] ) ( int ) const ; /* the above line declares an array called functionpointers that has three ( 3 ) elements which are all pointers ( * ) to functions in the scope of the class maths ( maths :: ) and take a single integer as parameter ( int ) and return nothing ( void ) and do not modify the contents of the class in anyway ( const ) */ public : maths () { functionpointers [ 0 ] = & maths :: square ; functionpointers [ 1 ] = & maths :: cube ; functionpointers [ 2 ] = & maths :: fourthpower ; } void executefunction ( int functionnumber, int inputforfunction ) { if ( functionnumber < 0 || functionnumber > 2 ) return ; ( this -> * functionpointers [ functionnumber ] ) ( inputforfunction ) ; // this line calls the function which is pointed ( * ) to by the functionnumber-th element of the functionpointers array which is a member of the object pointed to by the current object pointer ( this ) and passes the function the value of the variable inputforfunction as a parameter } } ; int main ( void ) { maths mathsinstance ; for ( int count = 0; count < 3; count ++ ) mathsinstance . executefunction ( count, 2 ) ; }