This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Member function using pointer to member function
- To: Volker Boerchers <boercher at physik dot uni-bremen dot de>
- Subject: Re: Member function using pointer to member function
- From: Todd Vierling <tv at pobox dot com>
- Date: Mon, 14 Sep 1998 10:43:14 -0400 (EDT)
- cc: egcs at cygnus dot com
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)