Hey, I want to pass a non static member function to another member of the same class.
Following basic example:
//---------------------------------
//functionclass.h
1 2 3 4 5 6 7 8
|
Class FunctionClass
{
public:
typedef void (FunctionClass::*funcPtr)(double,double*,double*,double*);
void innerfcn1(double a, double* b, double* c, double* d);
void innerfcn2(double a, double* b, double* c, double* d);
void outerfcn(funcPtr passingfunctionpointer,double e, double* f,double* g, double* h);
}
|
//---------------------------------
//functionclass.cpp
1 2 3 4 5 6 7 8 9
|
#include functionclass.h
...
outerfcn(funcPtr passingfunctionpointer,double e, double* f,double* g, double* h){
...
//This should call the passed function (either innerfcn1 or innerfcn2)
(this->*passingfunctionpointer)(e,f,g,e);
...
}
|
//---------------------------------
//main.cpp
1 2 3 4 5 6
|
#include functionclass.h
int main(){
...
FunctionClass::outerfcn(FunctionClass::innerfcn1,i,j,k,l);
...
}
|
I used the method of helios and no more compiler issues.
Unfortunately now I have the problem if I initialize a matrix with double** matrix= ...malloc....
and I call a function with (this->*passingfunctionpointer)(e,f,g,e);,
than the memory of the matrix is affected eventhough, it's not manipulated within the function or even given to the function. Following code sequence.
init the matrix with zeros -> Memory shows just zeros
Call of the function with the function pointer (this->*passingfunctionpointer)(e,f,g,e):
The passed variables don't have any relation with the matrix or its memory.
ALso the matrix isn't called within the function.
After the function call:
The matrix is pointing to crazy places in some rows.
No idea what the heck is going on.
Can you help me?
Thanks in advance