Please help: The following compiles in MT4 but not MT5: void demofunc( double & arr[][]) { }
You can't use this syntax for multidimensional array parameters in MT5. Second dimension must be specified. Otherwise, use classes or array of structs with arrays.
Yep.
struct my_struct { double second_dimension[]; }; void OnStart() { my_struct first_dimension[2]; ArrayResize(first_dimension[0].second_dimension,3); first_dimension[0].second_dimension[0]=0; first_dimension[0].second_dimension[1]=1; first_dimension[0].second_dimension[2]=2; ArrayResize(first_dimension[1].second_dimension,2); first_dimension[1].second_dimension[0]=3; first_dimension[1].second_dimension[1]=4; demofunc(first_dimension); } void demofunc(my_struct& first_dimension[]) { for(int f=0; f<ArraySize(first_dimension); f++) for(int s=0; s<ArraySize(first_dimension[f].second_dimension); s++) printf("[%i][%i] = %f",f,s,first_dimension[f].second_dimension[s]); }
Yep.
Thank you @Stanislav Korotky and @honest_knave for the excellent and definitive answers.
Thank you @honest_knave for such a great solution. It compiles perfectly in MT5.
I'm always impressed with the brainpower and quick responses on this forum.
Thanks again,
Robox
Multi-dimensional arrays are very poor and almost useless with mql5.
Oddly enough ArraySort lets you pass multi dimensional arrays and still works correctly on MQL5.
But you can't use (void &array[]) as user defined parameters of course
Tell me how to sort a multi-dimensional array in DESCENDING order with ArraySort() ?
Normally you use arrays to interate through them. If you need a sorted array in descending order, do ArraySort and then just iterate in reverse order, from n-1 to 0-th index.
Yeah for sure I know you can iterate in reverse order. That's not an answer to my question ;-)
Hello,
The following function compiles in MT4 (build 1045) (per @whroeder1 ), but not in MT5 (build 1545):
Does anybody else know why this would compile in MT4 but not in MT5?
What is the correct syntax for defining a function in MT5 that accepts as a parameter a two-dimensional array with both dimension lengths unknown, or is it even possible?
Note that I would like this function to accept a two-dimensional array whose second dimension length could be any value, so changing the code above to arr[][10] instead of arr[][] wouldn't work for me.
I asked this question yesterday in an old thread that seemed the most relevant ( https://www.mql5.com/en/forum/87545 ), but there's been no solution proposed for MT5, so I am posting this question in it's own thread.
Thank you very much in advance,
Robox