据我所知,MQL4中不存在函数指针。
作为一种变通方法,我使用:
// included for both caller as callee side
class Callback{
public: virtual void callback(){ return; }
}然后在从中传递回调的源代码中:
class mycb : Callback{
public: virtual void callback(){
// call to whatever function needs to be called back in this source
}mcbi;现在可以按如下方式传递mcbi:
afunction(){
fie_to_receive_callback((Callback *)mycbi);
} 接收方可以回调为:
fie_to_receive_callback(mycb *mcbi){
mcbi.callback(); // call the callback function
}在mql4中有没有更简单的方法来传递函数回调?
发布于 2019-05-16 01:38:37
下面是一个示例:
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, subtraction);
Print(n);
return(INIT_FAILED); //just to close the expert
}https://stackoverflow.com/questions/29473161
复制相似问题