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


On Mon, 14 Sep 1998, Volker Boerchers wrote:

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

In order to use a pointer to a member function, you must attach it to an
object so that the function has something to use for the "this" argument (so
that the function knows where local storage and so forth is).

Here, you'd use "this->*func(t)" to achieve the desired result.
In practice, you'd probably want to pass a reference to the object in
question, such as:

double A::ff(A& a, double (A::*func)(double), double t) {
  return a.*func(t);
}

-- 
-- Todd Vierling (Personal tv@pobox.com; Bus. todd_vierling@xn.xerox.com)



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