Hi folks,
I am learning member function pointers, wrote following program to understand typedef of function (of other class eg: test) inside other class(eg: exam) and then its access.

I have tried to use (e.*m)(8) but its gave
err:‘m’ was not declared in this scope

Could you please tell me how to call function 'add' using e.m
I have added comments inline for reference

using namespace std;

class test
int add(int k){cout<<"test::add"<<endl;
return k+1;


class exam
typedef int (test::*ptr)(int);
ptr m;

int main()
exam e;
test t;
e.m = &test::add;
(e.m)(8); //Err:must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘e.exam::m (...)’, e.g. ‘(... ->* e.exam::m) (...)’

 /** followed (function_ptr)(arg) . what is the correct way to call add using e.m **/
return 0;

Last edited by pushpat; 4Jul2012 at 14:18..