problem loop over 2 dimensional array

 


Hello,

 I'm trying to loop over a 2 dimentional array but I get "invalid array access" when trying to access the second array?

Am I doing it wrong?

 

This is my code. The highlighted code gives the error.

 

Any idea?

 

Thanks! 

 

 void ComputePPRZ(CProjection* &clusters[][], CProjection* &prz[]) {
        for (int i=0; i<ArraySize(clusters); i++) {
                ...
                for (int j=0; ArraySize(clusters[i]); j++) {
                        ...
                }
        }
}
 
  1. ArraySize "returns the number of elements of a selected array" which means for a 2x3 array you get 6, not the number of either dimension. ArrayRange - Array Functions - MQL4 Reference
  2. clusters[i] is illegal as clusters is a two dimensional array, not an array of arrays.
 
WHRoeder:
  1. ArraySize "returns the number of elements of a selected array" which means for a 2x3 array you get 6, not the number of either dimension. ArrayRange - Array Functions - MQL4 Reference
  2. clusters[i] is illegal as clusters is a two dimensional array, not an array of arrays.

Ok, Thanks for your answer!


I can't test it at the moment but would this work?


void ComputePPRZ(CProjection* &clusters[][], CProjection* &prz[]) {
        for (int i=0; i<ArrayDimension(clusters); i++) {
                ...
                for (int j=0; ArrayRange(clusters, i); j++) {
                        ...
                }
        }
}
Reason: