Member function using pointer to member function

Timothy Ritchey
Mon Sep 14 11:13:00 GMT 1998

> 13  double A::ff(double (A::*func)(double), double t)
> 14  {
> 15    return func(t);
> 16  }

> Who is wrong; what can i do to make it work?

int this case, I believe you need to tell it which instantiation you
want it to call the function for. you will find that this will compile
and run:

double A::ff(double (A::*func)(double), double t)
  return (this->*func)(t);

notice the use of parenthises to deal with precedence. Anyway, the
pointer to member function is a reference to the function relative to
its object. As an analogy, imagine you are passing in an index to an
array - you still need to tell it which array you want it to deal with.
BTW this is not the case with static member functions, which act like
normal pointers to functions.


More information about the Gcc mailing list