Passing member function to member functions

Hey,
it would be really nice, if you could help me with this head aching problem:
How can I pass member functions to other member functions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Class Integration{
public:
double* variableinclass1;
double* variableinclass2;
typedef void (Integration::*funcPtr_func)(double,double*,double*,double*);
functionToIntegrate1(double,double*,double*,double*){d=variableinclass1};
functionToIntegrate2(double,double*,double*,double*){d=variableinclass2};
double integrate(funcPtr_fun,double a,double*b,double*c,double*d,double*result){
   this->(*funcPtr_fun)(a,b,c,d);
   result=d;
};
void run(double,double*,double*,double*){
double result [2];
integrate(&functionToIntegrate1,a,b,c,d,result);
printf("Function1 integrated=(%f,%f)",result[0],result[1]);
integrate(&functionToIntegrate2,a,b,c,d,result);
printf("Function2 integrated=(%f,%f)",result[0],result[1]);
};

}


So basically the aim is to give the integrator the functions to integrate.
These should be done nonstatic,as the functionsToIntegrate contain Class variables?!
The call like displayed in run just works, if the functionsToIntegrate are static (ISO c++ forbids taking the adress of an unqualified parenthesized non-static member function to form a pointer to member funtion).
Any ideas, how to handle this and how to do it in a calculation time efficient way?
Thank you very much for your help in advance.

Last edited on
Simple example of passing members around:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

struct foo
{
    using fptr = int (foo::*)(int);
    int do_stuff(fptr f, int x)
    {
        return (this->*f)(x) + 2;
    }

    int run(int x) { return x + 1; }
};

int main()
{
    foo a;
    std::cout << a.do_stuff(&foo::run, 0);
}

Topic archived. No new replies allowed.