Pointers to Functions
I don't think you can have such beasts in the MQL code, but you would need to enumerate your functions and e.g. use a switch statement to map function number to function call. It might look partly like this:
#define OPaddition 45
#define OPsubtraction 312
int minus = OPsubtraction;
int operation(int x,int y,int op) {
switch ( op ) {
case OPaddition: return addition( x, y );
case OPsubtraction: return subtraction( x, y );
}
return( 3 );
}
#define OPaddition 45
#define OPsubtraction 312
int minus = OPsubtraction;
int operation(int x,int y,int op) {
switch ( op ) {
case OPaddition: return addition( x, y );
case OPsubtraction: return subtraction( x, y );
}
return( 3 );
}
Thanks for you help
IN BHM:
Thanks for you help
Thanks for you help
This post is old, but since the subject is unanswered and it is relevant even to this day - this is how you use function pointers in MQL4:
// pointer to functions typedef int(*MyFuncType)(int,int); int addition (int a, int b) { return (a+b); } int subtraction (int a, int b) { return (a-b); } int operation (int x, int y, MyFuncType myfunc) { int g; g = myfunc(x,y); return (g); } int OnInit() { int m,n; m = operation (7, 5, addition); n = operation (20, m, minus); Print(n); return(INIT_FAILED); //just to close the expert }
How is can this be done in MQL?