MQL does not support function pointers. MQL just looks like C/C++ but it is its own language. Read the documentation. Don't just assume that it works like C/C++.
It does on the latest builds, that's why this code works:
int OnInit() { Callback x = getCallback(); x(1); return INIT_SUCCEEDED; }
The other one is just a shortcut, the MQL5's parser is not recognizing that getCallback's result is a function pointer/descriptor.
int OnInit() { // This is equivalent to the other code. getCallback()(1); return INIT_SUCCEEDED; }
- www.mql5.com
Ok, that that is news to me! I stand corrected then!
EDIT: At which build did this start?
EDIT2: Looks like I have been blind! Apparently this has been available for many years now. I looked at a 2017 documentation file and it was there too. Guess I was not doing a very good job of keeping up-to-date on things.
Ok, that that is news to me! I stand corrected then!
EDIT: At which build did this start?
EDIT2: Looks like I have been blind! Apparently this has been available for many years now. I looked at a 2017 documentation file and it was there too. Guess I was not doing a very good job of keeping up-to-date on things.
I did find this some days ago too, got excited to implement an event emitter and found this minor issue, which wasn't that bad,
I was able to do it but it might get other people by surprise too. Still love MQL5, it is getting closer and closer to C++.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
A workaround is to create a temporary variable: