problem loop over 2 dimensional array

Back to topics list To post a new topic, please log in or register
avatar
2
murimons 2016.08.01 22:52
 


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++) {
                        ...
                }
        }
}

 

 

 

avatar
12998
WHRoeder 2016.08.02 03:56 #
 
  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.
avatar
2
murimons 2016.08.02 09:26 #
 
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++) {
                        ...
                }
        }
}
Back to topics list  

To add comments, please log in or register