typedef int (*TFunc)(int,int);
TFunc func_ptr;
int sub(int x,int y) { return(x-y); }
int add(int x,int y) { return(x+y); }
int neg(int x) { return(~x); }
func_ptr=sub;
Print(func_ptr(10,5));
func_ptr=add;
Print(func_ptr(10,5));
func_ptr=neg; // error: neg is not of int (int,int) type
Print(func_ptr(10)); // error: there should be two parameters
Pointers to functions can be stored and passed as parameters. You cannot get a pointer to a non-static class method.
함수포인터 지원된건 MetaTrader 5 build 1325 (2016년)이후 부터이므로 2016년 이후 배포된 MQL5 에서도 당연 사용가능.
한편, 함수포인터는 MQL5 에서 함수 인자로 전달하여 콜백 용도로 사용가능하나, DLL 함수 import 하여 DLL 에서 제공하는 함수인자로 함수 포인터 전달 불가함.
https://www.mql5.com/en/forum/37632
how to declare and call a function with callback function pointer as parameter imported from dll?
for example: here is a dll named tclient.dll, which include a function below: any thoughts? thanks a lot...
www.mql5.com
첫등록 : 2019년 5월 13일
최종수정 :
본 글 단축주소 : https://igotit.tistory.com/2162
'트레이딩 > 메타트레이더 코딩' 카테고리의 다른 글
MQL5. Arrays. 배열 (0) | 2019.05.17 |
---|---|
MQL5. struct. 구조체, DLL 함수인자에 구조체 전달 방법 (0) | 2019.05.16 |
MQL5. function pointer (0) | 2019.05.13 |
MQL5. EventChartCustom (0) | 2019.05.11 |
MQL5. Custom Indicator (3) | 2019.05.10 |
MQL5. 소켓통신 (0) | 2019.05.09 |
댓글0