Dr Matthias Hammelsbeck:
Hi,
may be I'm a little bit foggy-brained. I'm stumbling on a simple MQL5 typedef statement.
Am' I stupid now? What is wrong with my code? I do not understand....
Thanks for every answer
Matthias
BTW: I'm using Metaeditor Build 2769
Nothing is wrong. It just doesn't work.
typedef can only be used for function pointer, despite what the documentation says.
I was glad to find this here too, so thanks.
Unfortunately this code example about function pointers doesn't compile either:
//--- declare a pointer to a function that accepts two int parameters typedef int (*TFunc)(int,int); //--- TFunc is a type, and it is possible to declare the variable pointer to the function TFunc func_ptr; // pointer to the function //--- declare the functions corresponding to the TFunc description int sub(int x,int y) { return(x-y); } // subtract one number from another int add(int x,int y) { return(x+y); } // addition of two numbers int neg(int x) { return(~x); } // invert bits in the variable //--- the func_ptr variable may store the function address to declare it later func_ptr=sub; Print(func_ptr(10,5)); func_ptr=add; Print(func_ptr(10,5)); func_ptr=neg; // error: neg does not have int (int,int) type Print(func_ptr(10)); // error: two parameters needed |
After that there is another function pointer example about buttons and dialogs but I didn't bother.
And this:
https://www.mql5.com/en/forum/313077
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
may be I'm a little bit foggy-brained. I'm stumbling on a simple MQL5 typedef statement.
Am' I stupid now? What is wrong with my code? I do not understand....
Thanks for every answer
Matthias
BTW: I'm using Metaeditor Build 2769