how do I now define 2-dim arrays in a mt4-mqh-file?

 

Function definition - what is wrong?

int getInt2Index(int i0, int& arr[][]){

causes '[' - invalid index value    Defines.mqh    581    36

Char 36 is the 2nd [

Even a

int getInt2Index(int i0, int& arr[,]){

causes a ',' - invalid index value    Defines.mqh    581    35

 

Those function declarations do not produce errors for me.

Can you post the entire file ?

 
gooly: Function definition - what is wrong?
int getInt2Index(int i0, int& arr[][]){
Only the first dimension can be variable.
 
WHRoeder:
gooly: Function definition - what is wrong?
Only the first dimension can be variable.
 Again, this is not a problem in my editor.. compiles fine, and produces the correct Comment on  screen
#property indicator_chart_window
#property strict


int getInt2Index(int i0, int& arr[][])
{
   int ret = ArraySize(arr) > 0 ? arr[0][0] : -1;
   
   Comment("Hello array[0][0]=", ret);
   return ret;
}


int OnInit()
{
   int      ret = INIT_SUCCEEDED;
   int      dataArr[1][2];
   
   dataArr[0][0] = 25;
   getInt2Index(20, dataArr);
   
   return ret;
}

int OnCalculate(
   const int rates_total,
   const int prev_calculated,
   const datetime &time[],
   const double &open[],
   const double &high[],
   const double &low[],
   const double &close[],
   const long &tick_volume[],
   const long &volume[],
   const int &spread[])
{
   return rates_total;
}
 
WHRoeder:
gooly: Function definition - what is wrong?
Only the first dimension can be variable.

1.) It is the definition of a function with a 2-dim array defined else where.

2.) Don't compile an EA, script or indicator, compile a mqh-file.

Now I am  facing something really new??

My original file causes the compiler error. I wanted to create a new mqh-file with this function - which compiles with no error??

I copied from the beginning till that function from the 'error-mqh' into the 'new-mqh' and eliminated some function that need others it compiles again with no error?

Ok I repeat this trick with renaming the old error-mqh and creating a new mqh with the original name and copied everything (ctrl-A, ctrl-C) from the error-mqh into the new mqh (Ctrl-A,Ctrl-V) and now it compiles with no error??

But another mqh-file that calls my now perfectly compiling new-mqh-file still throws the above mentioned error?? Ok needed to reaped the procedure and now it works.

Hmm - hard to understand!

Looks a bit like an IKEA wardrobe after some time they have to renewed.

 
gooly:

1.) It is the definition of a function with a 2-dim array defined else where.

2.) Don't compile an EA, script or indicator, compile a mqh-file.



Again, I have no problem compiling this in mqh file and then including that elsewhere

Very odd

Reason: