This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Member function using pointer to member function


> 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.

cheers,
tim


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]