How to pass a static member function to another class?

Hey,

I want to pass a static member funcion to a function pointer in another class.
To check the passing of the function, we set sysfctinb in B to NULL.
As result, the code compiles, but in assignFunction4B the static member function is not assigned properly.
The sysfctinb function pointer in B stays NULL.
I need to do this with pointers, as I use further classes, whos functions I want to be able to assign to do1();
What am I missing?
Thanks a lot in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Class A{
public:
...
    static void sysfct(double* var1,double* var2);
    void assignFunction4B(void(*func)(double*,double*)){
    func=&A::sysfct; //DOESN'T PASS ANYTHING???
    };
...
}
Class B{
public:
...
    A elementofA;
    typedef  void (*funcPtr)(double*,double*);
    funcPtr sysfctinb;

    B(){this->funcPtr=NULL};
    int do1(funcPtr passedfunction);
    init(){elementofA.assignFunction4B(sysfctinb)};
...
}
int main(){
   ...
   B elementofB;
   elementofB.init();
   ...
}


Last edited on
void assignFunction4B(void(*func)(double*,double*)){
func is a local varable here. Any changes to it will not be reflected in caller.

You can:
1) Pass pointer to pointer and assigne value to dereferenced pointer
2) Pass reference to pointer
3) Do not pass anything, return pointer from function and let caller figure out what to do with it.
How can I create 2) ?
I tried following but stil have the same problem:

void assignFunction4B(void(*&func)(double*,double*)){
func=&A::sysfct; //DOESN'T PASS ANYTHING???
};
Last edited on
1
2
3
void assignFunction4B(void(*&func)(double*,double*)){
func=&A::sysfct; //DOESN'T PASS ANYTHING???
};
it does: http://coliru.stacked-crooked.com/a/e3bb107cd9897ccf
Thanks. Works perfectly fine. There was another issue with a virtual function.
Topic archived. No new replies allowed.